Submission #68311

#TimeUsernameProblemLanguageResultExecution timeMemory
68311thebes구경하기 (JOI13_watching)C++14
100 / 100
513 ms16668 KiB
#include <bits/stdc++.h> using namespace std; const int MN = 2002; int pos[MN], N, P, Q, i, lo, hi, l, r, k, nxt[MN], nxt2[MN], dp[MN][MN]; int solve(int n,int rem){ if(n == N+1) return 0; else if(dp[n][rem]!=-1) return dp[n][rem]; if(rem) dp[n][rem]=min(solve(nxt[n],rem-1),solve(nxt2[n],rem)+1); else dp[n][rem]=solve(nxt2[n],rem)+1; return dp[n][rem]; } bool check(int w){ for(l=r=k=1;l<=N;l++){ while(r<=N&&pos[r]-w+1<=pos[l]) r++; while(k<=N&&pos[k]-2*w+1<=pos[l]) k++; nxt[l] = r; nxt2[l] = k; } memset(dp, -1, sizeof(dp)); return solve(1,P)<=Q; } int main(){ for(scanf("%d%d%d",&N,&P,&Q),i=1;i<=N;i++) scanf("%d",&pos[i]); P = min(P, N); sort(pos+1,pos+N+1); lo = 1, hi = 1e9+7; while(lo < hi){ int m = lo+hi>>1; if(check(m)) hi=m; else lo=m+1; } printf("%d\n",hi); return 0; }

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:29:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = lo+hi>>1;
           ~~^~~
watching.cpp:23:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(scanf("%d%d%d",&N,&P,&Q),i=1;i<=N;i++)
      ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
watching.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&pos[i]);
   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...