Submission #187539

#TimeUsernameProblemLanguageResultExecution timeMemory
187539dndhkWatching (JOI13_watching)C++14
50 / 100
1074 ms556 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAX_N = 2002; const ll INFLL = 10000; int N, P, Q; vector<ll> v; list<pii> dq[2][MAX_N+1]; void add(int idx, int x, int y, int z){ while(!dq[idx][x].empty() && dq[idx][x].back().first>=z){ dq[idx][x].pop_back(); } dq[idx][x].push_back({z, y}); } bool chk(ll x){ for(int i=0; i<=N; i++){ while(!dq[0][i].empty()) dq[0][i].pop_back(); while(!dq[1][i].empty()) dq[1][i].pop_back(); } dq[0][0].pb({0, 0}); //cout<<x<<endl; int r1=0, r2=0, k; for(int i=0; i<=N; i++){ while(r1<v.size()-1 && v[r1+1]<=v[i+1]+x-1LL){ r1++; } while(r2<v.size()-1 && v[r2+1]<=v[i+1]+2LL*x-1LL){ r2++; } bool tf = true; for(int j=min(i, P); j>=0; j--){ while(!dq[0][j].empty() && dq[0][j].front().second<i) dq[0][j].pop_front(); while(!dq[1][j].empty() && dq[1][j].front().second<i) dq[1][j].pop_front(); if(dq[0][j].empty()){ if(!dq[1][j].empty()) k = dq[1][j].front().first; else continue; }else{ if(dq[1][j].empty()) k = dq[0][j].front().first; else{ k = min(dq[0][j].front().first, dq[1][j].front().first); } } tf = false; if(i==N){ if(j<=P && k<=Q) return true; }else{ if(k>Q) continue; add(0, j+1, r1, k); add(1, j, r2, k+1); } } if(tf) break; } return false; } int main(){ scanf("%d%d%d", &N, &P, &Q); v.pb(0); for(int i=1; i<=N; i++){ ll x; scanf("%lld", &x); v.pb(x); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); sort(v.begin(), v.end()); N = v.size()-1; ll s = 1LL, e = 1000000000LL, m; while(s<e){ m = (s+e)/2LL; if(chk(m)){ e = m; }else{ s = m+1; } } printf("%lld", s); }

Compilation message (stderr)

watching.cpp: In function 'bool chk(ll)':
watching.cpp:34:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(r1<v.size()-1 && v[r1+1]<=v[i+1]+x-1LL){
         ~~^~~~~~~~~~~
watching.cpp:37:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(r2<v.size()-1 && v[r2+1]<=v[i+1]+2LL*x-1LL){
         ~~^~~~~~~~~~~
watching.cpp: In function 'int main()':
watching.cpp:68:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &P, &Q); 
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll x; scanf("%lld", &x);
         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...