Finished c and d, e doesn't check for faulty arrangements
This commit is contained in:
@@ -2,22 +2,57 @@
|
|||||||
|
|
||||||
using namespace std;
|
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(){
|
int main(){
|
||||||
ios::sync_with_stdio(0);
|
ios::sync_with_stdio(0);
|
||||||
cin.tie(0);
|
cin.tie(0);
|
||||||
|
|
||||||
int t;
|
int n;
|
||||||
cin >> t;
|
cin >> n;
|
||||||
|
|
||||||
for(int tc = 1; tc <= t; ++tc){
|
movelist.reserve(n);
|
||||||
test_case(tc);
|
|
||||||
|
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;
|
cout << flush;
|
||||||
|
|
||||||
|
|||||||
@@ -2,22 +2,56 @@
|
|||||||
|
|
||||||
using namespace std;
|
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(){
|
int main(){
|
||||||
ios::sync_with_stdio(0);
|
ios::sync_with_stdio(0);
|
||||||
cin.tie(0);
|
cin.tie(0);
|
||||||
|
|
||||||
int t;
|
int n;
|
||||||
cin >> t;
|
cin >> n;
|
||||||
|
|
||||||
for(int tc = 1; tc <= t; ++tc){
|
vector<pair<ll, ll>> cities(n);
|
||||||
test_case(tc);
|
|
||||||
|
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;
|
cout << flush;
|
||||||
|
|
||||||
|
|||||||
@@ -2,23 +2,53 @@
|
|||||||
|
|
||||||
using namespace std;
|
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(){
|
int main(){
|
||||||
ios::sync_with_stdio(0);
|
ios::sync_with_stdio(0);
|
||||||
cin.tie(0);
|
cin.tie(0);
|
||||||
|
|
||||||
int t;
|
int n, m;
|
||||||
cin >> t;
|
cin >> n >> m;
|
||||||
|
|
||||||
for(int tc = 1; tc <= t; ++tc){
|
if(n != m){
|
||||||
test_case(tc);
|
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;
|
cout << flush;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user