Submission #527943

#TimeUsernameProblemLanguageResultExecution timeMemory
527943tabrFinding Routers (IOI20_routers)C++17
100 / 100
6 ms628 KiB
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

#ifdef tabr
function<int(int)> use_detector;
#else
#include "routers.h"
#endif

vector<int> find_routers(int l, int n, int) {
    vector<int> a(n - 1);
    map<int, int> mp;
    auto Ask = [&](int x) {
        if (!mp.count(x)) {
            mp[x] = use_detector(x);
        }
        return mp[x];
    };
    for (int i = 0; i < n - 1; i++) {
        int low = 0;
        int high = l;
        while (high - low > 1) {
            int mid = (high + low) >> 1;
            if (Ask(mid) <= i) {
                low = mid;
            } else {
                high = mid;
            }
        }
        a[i] = low;
    }
    vector<int> ans(n);
    for (int i = 1; i < n; i++) {
        ans[i] = 2 * a[i - 1] - ans[i - 1];
    }
    return ans;
}

#ifdef tabr
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n = 5;
    int l = 30;
    vector<int> a = {0, 2, 4, 18, 28};
    use_detector = [&](int x) {
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (abs(a[i] - x) < abs(a[ans] - x)) {
                ans = i;
            }
        }
        return ans;
    };
    debug(find_routers(l, n, 0));
    return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...