Submission #765218

#TimeUsernameProblemLanguageResultExecution timeMemory
765218yusuf12360Watching (JOI13_watching)C++14
0 / 100
3 ms352 KiB
#include<bits/stdc++.h> using namespace std; vector<int> a; int n; int binser(int x) { int l=0, r=n-1, ans=0; while(l<=r) { int mid=l+r>>1; if(a[mid]<x) ans=mid, l=mid+1; else r=mid-1; } return ans; } bool can(int w, int p, int q) { int idx=0; while(idx<n) { if(p>1 && q) { int BIG=binser(a[idx]+2*w); if(BIG==n-1) return 1; int SMALL=binser(a[idx]+w); if(SMALL==n-1) return 1; SMALL=binser(a[SMALL+1]+w); if(SMALL==n-1) return 1; if(SMALL>BIG) p-=2, idx=SMALL; else q--, idx=BIG; } else if(p && q) { int BIG=binser(a[idx]+2*w), SMALL=binser(a[idx]+w); if(BIG==n-1 || SMALL==n-1) return 1; if(BIG==SMALL) p--, idx=SMALL; else q--, idx=BIG; } else if(p) idx=binser(a[idx]+w), p--; else if(q) idx=binser(a[idx]+2*w), q--; else return 0; idx++; } return 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int p, q; cin >> n >> p >> q; a.resize(n); for(int &p : a) cin >> p; sort(a.begin(), a.end()); int l=1, r=1e9, w=1e9; while(l<=r) { int mid=l+r>>1; if(can(mid, p, q)) w=mid, r=mid-1; else l=mid+1; } cout << w << '\n'; return 0; }

Compilation message (stderr)

watching.cpp: In function 'int binser(int)':
watching.cpp:8:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    8 |   int mid=l+r>>1;
      |           ~^~
watching.cpp: In function 'int main()':
watching.cpp:46:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |   int mid=l+r>>1;
      |           ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...