# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941656 | benjaminkleyn | Finding Routers (IOI20_routers) | C++17 | 4 ms | 856 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |