제출 #438789

#제출 시각아이디문제언어결과실행 시간메모리
438789MilosMilutinovicWatching (JOI13_watching)C++14
100 / 100
286 ms16840 KiB
#include <bits/stdc++.h> using namespace std; const int N=2050; int n,p,q,a[N],dp[N][N]; bool Check(int w){ memset(dp,1e9,sizeof dp); dp[0][0]=0; int x=0,y=0; for(int i=1;i<=n;i++){ while(a[i]-a[x+1]>=w)x++; while(a[i]-a[y+1]>=2*w)y++; for(int j=0;j<=n;j++){ dp[i][j]=dp[x][j]+1; if(j>0)dp[i][j]=min(dp[i][j],dp[y][j-1]); } } for(int j=0;j<=min(n,q);j++){ if(dp[n][j]<=p)return true; } return false; } int main(){ scanf("%i %i %i",&n,&p,&q); for(int i=1;i<=n;i++)scanf("%i",&a[i]); sort(a+1,a+n+1); int bot=1,top=1e9,ans=1e9; while(bot<=top){ int mid=bot+top>>1; if(Check(mid))ans=mid,top=mid-1; else bot=mid+1; } printf("%i",ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

watching.cpp: In function 'int main()':
watching.cpp:31:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |         int mid=bot+top>>1;
      |                 ~~~^~~~
watching.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%i %i %i",&n,&p,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
watching.cpp:27:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     for(int i=1;i<=n;i++)scanf("%i",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...