Submission #614200

#TimeUsernameProblemLanguageResultExecution timeMemory
614200StrawHatWessThe Big Prize (IOI17_prize)C++17
20 / 100
83 ms2036 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i,a,b) for(int i=a; i<b; i++) typedef vector<int>vi; #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) typedef pair<ll,ll>pi; typedef vector<pi>vpi; #define fi first #define se second template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const ll INF=1e18; //------------------------------------- const int B=450; const int MX=2e5+10; int N,X=0; unordered_map<int,int>mn,mx; vi L(MX,-1), R(MX,-1); vi query(int i){ if(L[i]==-1){ vi vec=ask(i); L[i]=vec[0]; R[i]=vec[1]; if(L[i]+R[i]==X){ if(!mn.count(L[i])) mn[L[i]]=i, mx[L[i]]=i; if(ckmin(mn[L[i]],i)){ int j=i+1; while(j<N && L[j]==-1){ L[j]=L[i], R[j]=R[i]; i++; } } if(ckmax(mx[L[i]],i)){ int j=i-1; while(j>=0 && L[j]==-1){ L[j]=L[i], R[j]=R[i]; j--; } } } } return vi{L[i],R[i]}; } int find_best(int N) { ::N=N; int idx; FOR(i,0,min(N,B)){ vi vec=query(i); if(vec[0]==0 && vec[1]==0) return i; if(ckmax(X,vec[0]+vec[1])) idx=i; } int done=0; while(idx<N){ vi tmp=query(idx); int l=idx, r=N-1, nxt=N; while(l<=r){ int m=(l+r)/2; vi vec=query(m); if(vec[0]==0 && vec[1]==0) return m; if(vec[0]+vec[1]<X) nxt=m, r=m-1; else{ if(vec[0]==tmp[0]) l=m+1; else r=m-1; } } while(nxt<N){ vi vec=query(nxt); if(vec[0]==0 && vec[1]==0) return nxt; if(vec[0]+vec[1]==X) break; nxt++; } idx=nxt; done++; } //assert(0); } /* 8 3 2 3 1 3 3 2 3 */ /* 10 3 3 2 3 3 3 1 2 3 3 */

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:112:1: warning: control reaches end of non-void function [-Wreturn-type]
  112 | }
      | ^
prize.cpp:85:12: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   85 |    int m=(l+r)/2;
      |          ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...