제출 #428415

#제출 시각아이디문제언어결과실행 시간메모리
428415Popax21Finding Routers (IOI20_routers)C++14
100 / 100
3 ms972 KiB
#include <stdio.h> #include <assert.h> #include <map> #include "routers.h" std::vector<int> cache; std::multimap<int, int> qs; int query(int p) { if(cache[p] >= 0) return cache[p]; int r = use_detector(p); cache[p] = r; qs.emplace(r, p); return r; } int bsearch(int l, int r, int n) { assert(l < r); if(l == r-1) return l; int m = l + (r - l) / 2; int mr = query(m); if(mr != n) return bsearch(l, m, n); else return bsearch(m, r, n); } std::vector<int> find_routers(int l, int n, int q) { cache.resize(l+1); std::fill(cache.begin(), cache.end(), -1); std::vector<int> rs(n); rs[0] = 0; int pr = 0; for(int c = 1; c < n; c++) { int lp = rs[pr]+1, rp = l+1; auto li = qs.lower_bound(pr), ri = qs.upper_bound(pr); if(li != qs.end() && lp < li->second) lp = li->second; if(ri != qs.end() && ri->second < rp) rp = ri->second; // printf("pr %d l %d r %d %d %d\n", pr, lp, rp, ri->first, ri->second); int p = bsearch(lp, rp, pr)+1; int r = query(p); rs[r] = 2*p - rs[pr]; if(r > pr) rs[r] -= 2; // printf("pr %d r %d p %d pp %d p' %d\n", pr, r, p, rs[pr], rs[r]); pr = r; } return rs; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...