Submission #285282

#TimeUsernameProblemLanguageResultExecution timeMemory
285282leductoanWatching (JOI13_watching)C++14
100 / 100
358 ms8696 KiB
#include<bits/stdc++.h> using namespace std; #define task "watching" #define lb lower_bound #define ub upper_bound #define ALL(v) (v).begin(),(v).end() #define zs(v) int((v).size()) #define fi first #define se second #define pb push_back #define mp make_pair #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,b,a) for(int i=(b),_a=(a);i>=_a;--i) #define FOR_(i,a,b) for(int i=(a),_b=(b);i<_b;++i) typedef long double ld; typedef long long ll; typedef pair<int,int> pii; const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; const ll mod=1000000007; /// 998244353 const int base=311; const int N=2e3+5; int n,s,l,dp[N][N]; ll a[N]; int check(int val) { for(int i=0;i<=s;++i) { for(int j=0;j<=l;++j) { dp[i][j]=-1; } } dp[0][0]=0; for(int i=0;i<=s;++i) { for(int j=0;j<=l;++j) { if(dp[i][j]==-1) continue; if(dp[i][j]==n) return true; int l=dp[i][j]+1, r=n; int id=-1; while(l<=r) { int mid=(l+r)>>1; if(a[mid]-a[dp[i][j]+1]+1<=val) id=mid, l=mid+1; else r=mid-1; } dp[i+1][j]=max(dp[i+1][j],id); l=dp[i][j]+1, r=n; id=-1; while(l<=r) { int mid=(l+r)>>1; if(a[mid]-a[dp[i][j]+1]+1<=2*val) id=mid, l=mid+1; else r=mid-1; } dp[i][j+1]=max(dp[i][j+1],id); } } return dp[s][l]>=n; } void biot() { cin>>n>>s>>l; if(s+l>=n) { cout<<1; return; } for(int i=1;i<=n;++i) cin>>a[i]; sort(a+1,a+n+1); int l=1, r=1e9, ans=0; // cout<<check(16)<<endl; while(l<=r) { int mid=(l+r)>>1; if(check(mid)) ans=mid,r=mid-1; else l=mid+1; } cout<<ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } biot(); }

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   92 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   93 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...