Submission #35031

#TimeUsernameProblemLanguageResultExecution timeMemory
35031dqhungdlWatching (JOI13_watching)C++14
100 / 100
519 ms17724 KiB
#include <bits/stdc++.h> using namespace std; int n,P,Q,a[2005],f[2005][2005]; bool Check(int w) { for(int i=0;i<=n;i++) for(int j=0;j<=P;j++) f[i][j]=1e9; f[0][0]=0; for(int i=1;i<=n;i++) { int id1,id2; for(int j=1;j<=i;j++) if(a[i]-a[j]+1<=w) { id1=j; break; } for(int j=1;j<=i;j++) if(a[i]-a[j]+1<=2*w) { id2=j; break; } for(int j=1;j<=P;j++) f[i][j]=min(f[i][j],f[id1-1][j-1]); for(int j=0;j<=P;j++) f[i][j]=min(f[i][j],f[id2-1][j]+1); } for(int j=0;j<=P;j++) if(f[n][j]<=Q) return true; return false; } int main() { cin>>n>>P>>Q; P=min(P,n); Q=min(Q,n); for(int i=1;i<=n;i++) cin>>a[i]; sort(a+1,a+n+1); int res,l=1,r=1e9; while(l<=r) { int mid=(l+r)/2; if(Check(mid)==true) { res=mid; r=mid-1; } else l=mid+1; } cout<<res; }

Compilation message (stderr)

watching.cpp: In function 'bool Check(int)':
watching.cpp:14:17: warning: 'id2' may be used uninitialized in this function [-Wmaybe-uninitialized]
         int id1,id2;
                 ^
watching.cpp:14:13: warning: 'id1' may be used uninitialized in this function [-Wmaybe-uninitialized]
         int id1,id2;
             ^
watching.cpp: In function 'int main()':
watching.cpp:58:14: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout<<res;
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...