Submission #713008

#TimeUsernameProblemLanguageResultExecution timeMemory
713008piOOEGame (APIO22_game)C++17
100 / 100
1363 ms52488 KiB
#include "game.h" #include <bits/stdc++.h> constexpr int N = 3e5 + 7, B = 8, inf = 1e9 + 7; int fromMe[N], toMe[N], used[2][N], n, k; //smallest from me, biggest to me std::vector<int> adj[N], rev[N]; bool found = false; int save[2][N], level[N]; void init(int n, int k) { ::n = n, ::k = k; for (int i = 0; i < n; ++i) { if (i >= k) { fromMe[i] = inf, toMe[i] = -inf; } else { fromMe[i] = toMe[i] = i; } level[i] = std::__lg(k); } memset(save[0], 0x3f, sizeof(save[0])); memset(save[1], -0x3f, sizeof(save[1])); } void dfs2(int v, int x); void dfs1(int v, int x) { if (found || v < k || fromMe[v] <= x) { return; } if ((fromMe[v] >> level[v] != toMe[v] >> level[v]) && (fromMe[v] >> level[v]) <= (x >> level[v])) { save[0][v] = std::min(save[0][v], x); return; } fromMe[v] = x; if (fromMe[v] <= toMe[v]) { found = true; return; } if ((toMe[v] >> level[v]) == (fromMe[v] >> level[v])) { level[v] -= 1; if (save[1][v] >= 0) { int s = save[1][v]; save[1][v] = -1; dfs2(v, s); } } for (int to : rev[v]) { dfs1(to, x); } } void dfs2(int v, int x) { if (found || v < k || toMe[v] >= x) { return; } if ((fromMe[v] >> level[v]) != (toMe[v] >> level[v]) && (toMe[v] >> level[v]) >= (x >> level[v])) { save[1][v] = std::max(save[1][v], x); return; } toMe[v] = x; if (fromMe[v] <= toMe[v]) { found = true; return; } if ((toMe[v] >> level[v]) == (fromMe[v] >> level[v])) { level[v] -= 1; if (save[0][v] <= k) { int s = save[0][v]; save[0][v] = k + 1; dfs1(v, s); } } for (int to : adj[v]) { dfs2(to, x); } } int add_teleporter(int u, int v) { if (u < k && v < k && u >= v) { return 1; } adj[u].push_back(v); rev[v].push_back(u); dfs1(u, fromMe[v]); dfs2(v, toMe[u]); return found; }
#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...