Submission #941657

#TimeUsernameProblemLanguageResultExecution timeMemory
941657benjaminkleynFinding Routers (IOI20_routers)C++17
100 / 100
4 ms780 KiB
#include <bits/stdc++.h> #include "routers.h" using namespace std; map<int, int> mem; int detect(int x) { if (mem.find(x) != mem.end()) return mem[x]; return mem[x] = use_detector(x); } bool check(int x, int i) { if (mem.find(x) != mem.end()) return mem[x] <= i; auto it = prev(mem.upper_bound(x)); return (it->second <= i); } vector<int> find_routers(int l, int n, int q) { l -= l % 2; mem = map<int, int>(); vector<int> ans(n, 0); mem[0] = 0; for (int i = 0, x = 0; i < n - 1; i++) { int prev = x; auto it = mem.find(x); while (next(it) != mem.end() && next(it)->second == i) it = next(it); x = it->first; for (int k = 20; k >= 0; k--) while (x + (1 << k) <= l && check(x + (1 << k), i) && detect(x + (1 << k)) == i) x += (1 << k); ans[i + 1] = x + (x - ans[i]); } return ans; }

Compilation message (stderr)

routers.cpp: In function 'std::vector<int> find_routers(int, int, int)':
routers.cpp:28:13: warning: unused variable 'prev' [-Wunused-variable]
   28 |         int prev = x;
      |             ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...