Submission #725412

#TimeUsernameProblemLanguageResultExecution timeMemory
725412SanguineChameleonGame (APIO22_game)C++17
60 / 100
4066 ms45608 KiB
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma") #include "game.h" #include <bits/stdc++.h> using namespace std; const int shift = 9; const int maxN = 3e5 + 20; int max_in[maxN]; int min_out[maxN]; vector<int> adj1[maxN]; vector<int> adj2[maxN]; bool done = false; int n, k; void init(int _n, int _k) { n = _n; k = _k; for (int i = 0; i < k; i++) { max_in[i] = i; min_out[i] = i + 1; } for (int i = k; i < n; i++) { max_in[i] = 0; min_out[i] = k + 1; } } void update_in(int u, int val); void update_out(int u, int val); void update_in(int u, int val) { if (done) { return; } bool diff = (max_in[u] >> shift) != (val >> shift); bool same = (max_in[u] >> shift) == (min_out[u] >> shift); max_in[u] = val; if (max_in[u] >= min_out[u]) { done = true; return; } if (diff) { for (auto v: adj1[u]) { if (max_in[u] > max_in[v]) { update_in(v, max_in[u]); } } } else if (same) { for (auto v: adj1[u]) { if (max_in[u] > max_in[v]) { update_in(v, max_in[u]); } } for (auto v: adj2[u]) { if (min_out[u] < min_out[v]) { update_out(v, min_out[u]); } } } } void update_out(int u, int val) { if (done) { return; } bool diff = (min_out[u] >> shift) != (val >> shift); bool same = (max_in[u] >> shift) == (min_out[u] >> shift); min_out[u] = val; if (max_in[u] >= min_out[u]) { done = true; return; } if (diff) { for (auto v: adj2[u]) { if (min_out[u] < min_out[v]) { update_out(v, min_out[u]); } } } else if (same) { for (auto v: adj1[u]) { if (max_in[u] > max_in[v]) { update_in(v, max_in[u]); } } for (auto v: adj2[u]) { if (min_out[u] < min_out[v]) { update_out(v, min_out[u]); } } } } int add_teleporter(int u, int v) { int val = max(max_in[u], (u < k ? u + 1 : 0)); if (val > max_in[v]) { update_in(v, val); } if (min_out[v] < min_out[u]) { update_out(u, min_out[v]); } adj1[u].push_back(v); adj2[v].push_back(u); return done; }
#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...