Submission #299989

#TimeUsernameProblemLanguageResultExecution timeMemory
299989pacha2880The Big Prize (IOI17_prize)C++17
20 / 100
79 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'; int lus; while(true) { //cout<<"sdac "<<pos<<'\n'; lo = pos + 1, hi = n - 1; while(lo <= hi) { mid = (lo + hi) / 2; auto ar = ask(mid); //cout<<mid<<' '<<ar[0]<<' '<<ar[1]<<'\n'; lus = 0; for(auto cat : le) { if(cat.f <= ar[0] + ar[1]) lus += cat.s; } if(ar[0] + ar[1] != can) { if(ar[0] + ar[1] == 0) return mid; if(ar[0] > lus) pos = mid, hi = mid - 1; else lo = mid + 1; } else { if(ar[0] > lus) hi = mid - 1; else lo = mid + 1; } } auto ar = ask(pos); if(ar[0] + ar[1] == 0) return pos; le[ar[0] + ar[1]] = ar[0]; } } // 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

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:64:31: warning: unused variable 'res' [-Wunused-variable]
   64 |  int lo = 0, hi = n - 1, mid, res;
      |                               ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...