Submission #1033061

#TimeUsernameProblemLanguageResultExecution timeMemory
1033061ZicrusComparing Plants (IOI20_plants)C++17
0 / 100
34 ms4124 KiB
#include <bits/stdc++.h> #include "plants.h" using namespace std; typedef long long ll; vector<ll> lnk; vector<int> a; ll find(ll a) { if (lnk[a] != a) lnk[a] = find(lnk[a]); return lnk[a]; } void unite(ll a, ll b) { a = find(a); b = find(b); lnk[b] = a; } bool same(ll a, ll b) { return find(a) == find(b); } void init(int k, vector<int> r) { ll n = r.size(); lnk = vector<ll>(n); for (int i = 0; i < n; i++) lnk[i] = i; for (int i = n-1; i >= 0; i--) { int o = (i+1) % n; if (r[i] == r[o]) unite(i, o); } a = vector<int>(n); for (int i = 0; i < n; i++) a[i] = r[i]; } int compare_plants(int x, int y) { ll n = a.size(); ll mul = 1; if (same((x-1+n)%n, y)) { x += n; swap(x, y); mul = -1; } if (!same(x, (y-1)%n)) return 0; return (a[x] ? -1 : 1) * mul; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...