Finished c and d, e doesn't check for faulty arrangements
This commit is contained in:
@@ -2,22 +2,57 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
void test_case(int tc){
|
||||
typedef long long ll;
|
||||
|
||||
set<int> learnedMoves;
|
||||
vector<pair<ll, vector<int>>> movelist;
|
||||
ll result = 0;
|
||||
|
||||
void handleMove(int move){
|
||||
auto s = learnedMoves.size();
|
||||
learnedMoves.insert(move);
|
||||
|
||||
if(s == learnedMoves.size()){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
result += movelist[move - 1].first;
|
||||
for(int neededMove : movelist[move - 1].second){
|
||||
handleMove(neededMove);
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
for(int tc = 1; tc <= t; ++tc){
|
||||
test_case(tc);
|
||||
movelist.reserve(n);
|
||||
|
||||
for(int i = 0; i < n; ++i){
|
||||
ll t;
|
||||
int k;
|
||||
|
||||
cin >> t >> k;
|
||||
|
||||
vector<int> neededMoves(k);
|
||||
|
||||
for(int j = 0; j < k; ++j){
|
||||
cin >> neededMoves[j];
|
||||
}
|
||||
movelist[i].first = t;
|
||||
movelist[i].second = neededMoves;
|
||||
}
|
||||
|
||||
result += movelist[n - 1].first;
|
||||
|
||||
for(int move : movelist[n - 1].second){
|
||||
handleMove(move);
|
||||
}
|
||||
|
||||
cout << result;
|
||||
|
||||
cout << flush;
|
||||
|
||||
|
||||
@@ -2,22 +2,56 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
void test_case(int tc){
|
||||
typedef long long ll;
|
||||
|
||||
set<pair<ll, ll>> spells;
|
||||
|
||||
ll gcd(ll a, ll b){
|
||||
if(b == 0){
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
return gcd(b, a % b);
|
||||
}
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
for(int tc = 1; tc <= t; ++tc){
|
||||
test_case(tc);
|
||||
vector<pair<ll, ll>> cities(n);
|
||||
|
||||
for(int i = 0; i < n; ++i){
|
||||
ll x, y;
|
||||
|
||||
cin >> x >> y;
|
||||
cities[i] = {x, y};
|
||||
|
||||
for(int j = 0; j < i; ++j){
|
||||
ll dx = cities[j].first - cities[i].first;
|
||||
ll dy = cities[j].second - cities[i].second;
|
||||
|
||||
if(dx == 0){
|
||||
spells.insert({0, 1});
|
||||
spells.insert({0,-1});
|
||||
} else if(dy == 0){
|
||||
spells.insert({1,0});
|
||||
spells.insert({-1, 0});
|
||||
} else{
|
||||
ll g = gcd(dx, dy);
|
||||
|
||||
dx /= g;
|
||||
dy /= g;
|
||||
|
||||
spells.insert({dx, dy});
|
||||
spells.insert({-1*dx, -1*dy});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << spells.size();
|
||||
|
||||
cout << flush;
|
||||
|
||||
|
||||
@@ -2,23 +2,53 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
void test_case(int tc){
|
||||
vector<bool> visitedNodes;
|
||||
vector<vector<int>> edgeList;
|
||||
|
||||
void dfs(int start){
|
||||
visitedNodes[start] = true;
|
||||
|
||||
for(int node : edgeList[start]){
|
||||
if(!visitedNodes[node]){
|
||||
dfs(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
for(int tc = 1; tc <= t; ++tc){
|
||||
test_case(tc);
|
||||
if(n != m){
|
||||
cout << 0 << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
visitedNodes.reserve(n+1);
|
||||
edgeList.reserve(n+1);
|
||||
|
||||
for(int i = 1; i <= m; ++i){
|
||||
int u, v;
|
||||
cin >> u >> v;
|
||||
|
||||
edgeList[u].push_back(v);
|
||||
}
|
||||
|
||||
long long result = 1;
|
||||
|
||||
for(int start = 1; start <= n; ++start){
|
||||
if(!visitedNodes[start]){
|
||||
result = (result * 2) % 998244353;
|
||||
|
||||
dfs(start);
|
||||
}
|
||||
}
|
||||
|
||||
cout << result;
|
||||
|
||||
cout << flush;
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user