제출 #492598

#제출 시각아이디문제언어결과실행 시간메모리
492598ToroTN구경하기 (JOI13_watching)C++14
100 / 100
910 ms16524 KiB
#include<bits/stdc++.h> using namespace std; int n,p,q,a,st,md,ed,dp[2005][2005],val,idx,st1,st2,type; vector<int> small[2005],large[2005],v; int main() { scanf("%d%d%d",&n,&p,&q); for(int i=1;i<=n;i++) { scanf("%d",&a); v.push_back(a); } sort(v.begin(),v.end()); st=1; ed=1e9; while(ed>=st) { md=(st+ed)/2; //printf("%d %d %d\n",st,md,ed); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { dp[i][j]=1e9; } } md=(st+ed)/2; for(int i=0;i<v.size()-1;i++) { val=v[i+1]+md-1; idx=upper_bound(v.begin(),v.end(),val)-v.begin()-1; //printf("%d %d\n",i,idx); small[idx].push_back(i); } //printf("\n"); for(int i=0;i<v.size()-1;i++) { val=v[i+1]+2*md-1; idx=upper_bound(v.begin(),v.end(),val)-v.begin()-1; //printf("%d %d\n",i,idx); large[idx].push_back(i); } //printf("\n"); st1=upper_bound(v.begin(),v.end(),v[0]+md-1)-v.begin()-1; st2=upper_bound(v.begin(),v.end(),v[0]+2*md-1)-v.begin()-1; //printf("%d %d\n",st1,st2); dp[st1][1]=min(dp[st1][1],0); dp[st2][0]=min(dp[st2][0],1); for(int i=1;i<n;i++) { for(int j=0;j<n;j++) { for(int k=0;k<small[i].size();k++) { if(j>0) { dp[i][j]=min(dp[i][j],dp[small[i][k]][j-1]); } } for(int k=0;k<large[i].size();k++) { dp[i][j]=min(dp[i][j],dp[large[i][k]][j]+1); } } } type=-1; for(int i=0;i<=min(p,2000);i++) { if(dp[n-1][i]<=q) { type=0; } } if(type==0) { ed=md-1; }else { st=md+1; } for(int i=0;i<n;i++) { small[i].clear(); large[i].clear(); } } //printf("%d %d %d\n",st,md,ed); printf("%d\n",st); }

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

watching.cpp: In function 'int main()':
watching.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for(int i=0;i<v.size()-1;i++)
      |                     ~^~~~~~~~~~~
watching.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i=0;i<v.size()-1;i++)
      |                     ~^~~~~~~~~~~
watching.cpp:53:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                 for(int k=0;k<small[i].size();k++)
      |                             ~^~~~~~~~~~~~~~~~
watching.cpp:60:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 for(int k=0;k<large[i].size();k++)
      |                             ~^~~~~~~~~~~~~~~~
watching.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     scanf("%d%d%d",&n,&p,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
watching.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         scanf("%d",&a);
      |         ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...