Submission #661502

#TimeUsernameProblemLanguageResultExecution timeMemory
661502sofija6Watching (JOI13_watching)C++14
100 / 100
843 ms63352 KiB
#include <bits/stdc++.h> #define ll long long #define MAXN 2010 using namespace std; ll a[MAXN],n,p,q; pair<ll,ll> dp[MAXN][MAXN]; ll Last(ll pos) { ll l=1,r=n,mid,ans; while (l<=r) { mid=(l+r)/2; if (a[mid]<=pos) { ans=mid; l=mid+1; } else r=mid-1; } return ans; } bool Check(ll w) { for (ll i=0;i<=n+1;i++) { for (ll j=0;j<=min(n,p);j++) dp[i][j]={0,LLONG_MAX}; } dp[1][0]={1,0}; for (ll i=1;i<=n;i++) { for (ll j=0;j<=min(n,p);j++) { if (!dp[i][j].first) continue; if (j<p) { ll pos=Last(a[i]+w-1); dp[pos+1][j+1].first=1; dp[pos+1][j+1].second=min(dp[pos+1][j+1].second,dp[i][j].second); } if (dp[i][j].second<q) { ll pos=Last(a[i]+2*w-1); dp[pos+1][j].first=1; dp[pos+1][j].second=min(dp[pos+1][j].second,dp[i][j].second+1); } } } for (ll i=0;i<=p;i++) { if (dp[n+1][i].first && dp[n+1][i].second<=q) return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> p >> q; for (ll i=1;i<=n;i++) cin >> a[i]; sort(a+1,a+1+n); ll l=1,r=1e9,mid,ans; while (l<=r) { mid=(l+r)/2; if (Check(mid)) { ans=mid; r=mid-1; } else l=mid+1; } cout << ans; return 0; }

Compilation message (stderr)

watching.cpp: In function 'long long int Last(long long int)':
watching.cpp:21:12: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   21 |     return ans;
      |            ^~~
watching.cpp: In function 'bool Check(long long int)':
watching.cpp:46:23: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |                 dp[pos+1][j].first=1;
      |                    ~~~^~
watching.cpp:40:23: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   40 |                 dp[pos+1][j+1].first=1;
      |                    ~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...