Submission #699592

#TimeUsernameProblemLanguageResultExecution timeMemory
699592uroskThe Big Prize (IOI17_prize)C++14
100 / 100
61 ms12232 KiB
#include "prize.h" #define here cerr<<"===========================================\n" #define dbg(x) cerr<<#x<<": "<<x<<endl; #include "bits/stdc++.h" //#include <ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/assoc_container.hpp> #define ld double #define ll int #define llinf 100000000000000000LL // 10^17 #define pb push_back #define popb pop_back #define fi first #define sc second #define endl '\n' #define pll pair<ll,ll> #define pld pair<ld,ld> #define sz(a) (ll)(a.size()) #define all(a) a.begin(),a.end() #define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} #define cer(a) {cerr<<#a<<": ";for(ll x_ : a) cerr<<x_<< " ";cerr<<endl;} #define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); using namespace std; #define maxn 200005 ll n; ll ans = -1; ll a[maxn][2],val[maxn]; set<ll> s[maxn]; void get(ll i){ vector<ll> v = ask(i); a[i][0] = v[0],a[i][1] = v[1]; val[i] = a[i][0] + a[i][1]; } void reshi(ll l,ll r){ if(l>r||(ans!=-1)) return; ll mid = (l+r)/2; get(mid); if(val[mid]==0){ ans = mid; return; } ll sum = val[mid]; auto it = s[sum].upper_bound(mid); ll lok = 1,rok = 1; if(it!=s[sum].end()){ ll j = *it; if(j>r&&a[j][0]-a[mid][0]==0) rok = 0; } if(it!=s[sum].begin()){ it--; ll j = *it; if(j<l&&a[mid][0]-a[j][0]==0) lok = 0; } s[sum].insert(mid); if(lok) reshi(l,mid-1); if(rok) reshi(mid+1,r); } int find_best(int N){ n = N; reshi(0,n-1); return ans; } /* 8 3 1 3 2 3 3 2 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...