Submission #782818

#TimeUsernameProblemLanguageResultExecution timeMemory
782818makanhuliaThe Xana coup (BOI21_xanadu)C++17
0 / 100
52 ms2400 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MAXN = 1e5 + 5; ll n, ans = 0, val[MAXN]; bool flag = true; ll cek(ll a, ll b, ll c) { if (a == 1) { if (b == 1) { if (c == 1) { return 2; } else { return 4; } } else { if (c == 1) { return 5; } else { return 3; } } } else { if (b == 1) { if (c == 1) { return 1; } else { return 7; } } else { if (c == 1) { return 6; } else { return 0; } } } } void update(ll state) { bitset<3> bs = state; ans += bs.count(); } int main(){ cin >> n; for (int i = 0; i < n-1; ++i) { ll tmp; cin >> tmp >> tmp; } for (int i = 1; i <= n; ++i) { cin >> val[i]; } for (int i = 1; i <= n; ++i) { if (!flag) { break ; } if (n-i+1 < 3) { if (n-i+1 == 2) { if (val[i] != val[i+1]) { flag = false; } break ; } else { if (val[i] == 1) { flag = false; } break ; } } else { ll state = cek(val[i], val[i+1], val[i+2]); bitset<3> bs = state; update(state); for (int j = 0; j < 3; ++j) { // Sebelum if (j == 2 && bs[j] && i != 1) { if (val[i-1] == 0) { flag = false; break ; } } // Sesudah if (j == 0 && bs[j] && i != n) { val[i+1] = val[i+1] ^ 1ll; } } } } if (flag) { cout << ans << "\n"; } else { cout << "impossible\n"; } return 0; }
#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...