Submission #381094

#TimeUsernameProblemLanguageResultExecution timeMemory
381094BlancaHMFinding Routers (IOI20_routers)C++14
100 / 100
3 ms620 KiB
#include <iostream> #include <vector> #include <unordered_map> #include "routers.h" using namespace std; vector<int> find_routers(int l, int n, int q) { vector<int> positions(n, -1); // Vamos buscando los routers uno a uno positions[0] = 0; int lo, hi, mid, k; unordered_map<int, int> calls; calls.reserve(4096); calls[0] = 0; calls[1] = 0; vector<int> low(n, 0), high(n, l); for (int i = 1; i < n; i++) { lo = max(positions[i-1], low[i-1]); hi = high[i]; k = lo; while(lo <= hi) { mid = lo + (hi-lo)/2; if (calls.find(mid) == calls.end()) { calls[mid] = use_detector(mid); for (int j = i; j <= calls[mid]; j++) high[j] = min(high[j], mid); low[calls[mid]+1] = max(low[calls[mid]+1], mid); } if (calls[mid] < i) { k = mid; lo = mid+1; } else hi = mid-1; } positions[i] = positions[i-1] + 2*(k - positions[i-1]); } return positions; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...