Submission #578731

#TimeUsernameProblemLanguageResultExecution timeMemory
578731Noam527Game (APIO22_game)C++17
100 / 100
1479 ms69632 KiB
#include <bits/stdc++.h> #include "game.h" const int OO = 0; const int OOO = 0; using namespace std; int n, k; vector<vector<int>> g, grev; vector<int> s, e; // s: maximum that reaches us // e: minimum that we can reach // s <= e as long as the answer is 0 (with s < e for all non-special vertices) void init(int nn, int kk) { g.clear(); grev.clear(); s.clear(); e.clear(); n = nn; k = kk; g.resize(n); grev.resize(n); s.resize(n, -1); e.resize(n, k); for (int i = 0; i < k; i++) { s[i] = i; e[i] = i; } } int add(int u, int v) { if (OO) { cout << "add " << u << " " << v << '\n'; } if (s[u] >= e[v]) return 1; if (s[u] > s[v]) { while (s[u] - s[v] >= e[v] - s[u]) { if (OO) { cout << "add " << u << " " << v << " updates forward\n"; } s[v] = (s[v] + e[v] + 1) / 2; for (const auto &i : g[v]) if (add(v, i)) return 1; } } if (e[u] > e[v]) { while (e[u] - e[v] >= e[v] - s[u]) { if (OO) { cout << "add " << u << " " << v << " updates backward\n"; } e[u] = (s[u] + e[u]) / 2; for (const auto &i : grev[u]) if (add(i, u)) return 1; } } return 0; } void brute_dfs(vector<int> &vis, int v) { if (vis[v]) return; vis[v] = 1; for (const auto &i : g[v]) brute_dfs(vis, i); } int brute() { vector<int> vis(n); for (int i = 0; i < k; i++) { for (auto &x : vis) x = 0; for (const auto &j : g[i]) brute_dfs(vis, j); for (int j = 0; j <= i; j++) if (vis[j]) return 1; } return 0; } int add_teleporter(int u, int v) { if (OO) { cout << "current s: "; for (const auto &i : s) cout << i << " "; cout << '\n'; cout << "current e: "; for (const auto &i : e) cout << i << " "; cout << '\n'; } if (u < k && v < k) { return u >= v; } g[u].push_back(v); grev[v].push_back(u); int x = add(u, v); if (OOO) { int y = brute(); if (x != y) { cout << "difference! " << x << " " << y << '\n'; return 2; } } return x; }

Compilation message (stderr)

game.cpp: In function 'int add_teleporter(int, int)':
game.cpp:83:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   83 |   for (const auto &i : s) cout << i << " "; cout << '\n';
      |   ^~~
game.cpp:83:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   83 |   for (const auto &i : s) cout << i << " "; cout << '\n';
      |                                             ^~~~
game.cpp:85:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   85 |   for (const auto &i : e) cout << i << " "; cout << '\n';
      |   ^~~
game.cpp:85:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   85 |   for (const auto &i : e) cout << i << " "; cout << '\n';
      |                                             ^~~~
#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...