Submission #299985

#TimeUsernameProblemLanguageResultExecution timeMemory
299985pacha2880The Big Prize (IOI17_prize)C++17
20 / 100
86 ms384 KiB
#include <bits/stdc++.h> #include <prize.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define mp make_pair #define pb push_back #define all(a) (a).begin(), (a).end() #define sz(a) a.size() #define md(a, b) ((a) % b + b) % b #define mod(a) md(a, MOD) #define srt(a) sort(all(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define f first #define s second #define forn(i, n) for(int i = 0; i < n; i++) #define fore(i, b, e) for(int i = b; i < e; i++) #define forg(i, b, e, m) for(int i = b; i < e; i+=m) //int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;} using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vll; //typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; //find_by_order kth largest order_of_key < const int tam = 100010; const int MOD = 1000000007; const int MOD1 = 998244353; const double EPS = 1e-9; const double PI = acos(-1); /*int er[] = {4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 3, 1, 4, 4, 4, 4, 2, 4, 4, 4, 3}; vector<int> ar(100034); int q; int n; vector<int> ask(int i) { q++; vector<int> res(2, 0); fore(j, 0, i) res[0] += ar[j] < ar[i]; fore(j, i + 1, 100034) res[1] += ar[j] < ar[i]; return res; } int find_best(int n); int main() { q = 0; fore(i, 0, 100000) ar[i] = 4; fore(i, 100000, 100034) ar[i] = er[i - 100000]; cout<<find_best(100034)<<'\n'; cout<<q<<'\n'; return 0; }*/ int find_best(int n) { int lo = 0, hi = n - 1, mid, res; pair<int, pair<int, int>> maxi{0,{0, 0}}; int q = 0; fore(i, 0, 475) { auto ar = ask(i); q++; if(ar[0] + ar[1] == 0) return i; maxi = max(maxi, mp(ar[0] + ar[1], mp(i, ar[0]))); } map<int, int> le; int can = maxi.f, pos = maxi.s.f; le[can] = maxi.s.s; //cout<<le<<'\n'; while(true) { //cout<<"sdac "<<pos<<'\n'; lo = pos + 1, hi = min(n - 1, pos + 1023), res = hi; auto er = ask(hi); q++; if(er[0] + er[1] == 0) return hi; if(er[0] + er[1] != can || er[0] > le[er[0] + er[1]]) while(lo <= hi) { mid = (lo + hi) / 2; auto ar = ask(mid); q++; //cout<<mid<<' '<<ar[0]<<' '<<ar[1]<<'\n'; if(ar[0] + ar[1] != can) { if(ar[0] + ar[1] == 0) { if(q > 7000) return -1; return mid; } if(ar[0] > le[ar[0] + ar[1]]) res = mid, hi = mid - 1; else lo = mid + 1; } else { if(ar[0] > le[ar[0] + ar[1]]) hi = mid - 1; else lo = mid + 1; } } pos = res; while(true) { auto ar = ask(pos); q++; if(ar[0] + ar[1] == 0) { if(q > 7000) return -1; return pos; } le[ar[0] + ar[1]] = ar[0]; if(ar[0] + ar[1] == can) { break; } pos++; } } } // read the question correctly (is y a vowel? what are the exact constraints?) // look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...