Submission #152300

#TimeUsernameProblemLanguageResultExecution timeMemory
152300mieszko11bThe Big Prize (IOI17_prize)C++14
20 / 100
103 ms5260 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; #define X first #define Y second using ii = pair<int, int>; int n; vector<int> V[200007]; ii ans(int i) { if(V[i].size() == 0) V[i] = ask(i); return {V[i][0], V[i][1]}; } int sum(int i) { return ans(i).X + ans(i).Y; } int worst_sum; int find_in_segment(int a, int b, int ok) { if(!ok) return -1; int mid1 = (a + b) / 2; if(sum(mid1) > sum(a - 1)) { while(sum(a) < sum(mid1)) { if(sum(a) == 0) return a; a++; } while(sum(b) < sum(mid1)) { if(sum(b) == 0) return b; b--; } if(a < mid1) { int x = find_in_segment(a + 1, mid1 - 1, ans(mid1).X - ans(a).X); if(x != -1) return x; } if(mid1 < b) { int x = find_in_segment(mid1 + 1, b - 1, ans(b).X - ans(mid1).X); if(x != -1) return x; } return -1; } int mid2 = (a + b) / 2; while(ans(mid1).X + ans(mid1).Y != sum(a - 1) && mid1 >= a) { if(ans(mid1).X + ans(mid1).Y == 0) return mid1; mid1--; } if(mid1 > a) { int x = find_in_segment(a, mid1 - 1, ans(mid1).X - ans(a - 1).X); if(x != -1) return x; } while(ans(mid2).X + ans(mid2).Y != sum(a - 1) && mid2 <= b) { if(ans(mid2).X + ans(mid2).Y == 0) return mid2; mid2++; } if(mid2 < b) { int x = find_in_segment(mid2 + 1, b, ans(b + 1).X - ans(mid2).X); if(x != -1) return x; } return -1; } int find_best(int n) { ::n = n; int total = ans(0).Y; V[n] = {total, 0}; if(total == 0) return 0; return find_in_segment(1, n - 1, total); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...