Submission #559075

#TimeUsernameProblemLanguageResultExecution timeMemory
559075groshiWatching (JOI13_watching)C++17
0 / 100
304 ms8632 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; int n,p,q; vector<int> Q; int dp[1020][1020]; bool check(int ile) { for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) dp[i][j]=1000000000; dp[0][0]=0; for(int i=1;i<=Q.size();i++) { int gdzie1=lower_bound(Q.begin(),Q.end(),Q[i-1]-2*ile+1)-Q.begin(); int gdzie2=lower_bound(Q.begin(),Q.end(),Q[i-1]-ile+1)-Q.begin(); for(int j=0;j<=p;j++) { if(j>0) dp[i][j]=min(dp[gdzie1][j]+1,dp[gdzie2][j-1]); else dp[i][j]=dp[gdzie1][j]+1; } } for(int i=0;i<=p;i++) if(dp[n][i]<=q) return 1; return 0; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin>>n>>p>>q; int x; for(int i=1;i<=n;i++) { cin>>x; Q.push_back(x); } sort(Q.begin(),Q.end()); int pocz=0,kon=1000000005,sre,ostd; while(pocz<kon) { sre=(pocz+kon)/2; if(check(sre)) { ostd=sre; kon=sre; } else pocz=sre+1; } cout<<ostd; return 0; }

Compilation message (stderr)

watching.cpp: In function 'bool check(int)':
watching.cpp:14:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i=1;i<=Q.size();i++)
      |                 ~^~~~~~~~~~
watching.cpp: In function 'int main()':
watching.cpp:54:11: warning: 'ostd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |     cout<<ostd;
      |           ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...