Submission #1123142

#TimeUsernameProblemLanguageResultExecution timeMemory
1123142hainam2k9Watching (JOI13_watching)C++20
100 / 100
260 ms16196 KiB
#include <bits/stdc++.h> #define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0) #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout) #define ll long long #define ull unsigned long long #define i128 __int128 #define db long double #define sz(a) ((int)(a).size()) #define pb emplace_back #define pf emplace_front #define pob pop_back #define pof pop_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define ins emplace using namespace std; const int MOD = 1e9+7, MAXN = 1e5+5; const string NAME = ""; int n,p,q,a[2005],dp[2005][2005]; inline int Front(int i, queue<int>& q){ if(q.empty()) return i; return q.front(); } void Print(queue<int> q){ while(!q.empty()) cout << q.front() << " ", q.pop(); cout << "\n"; } bool check(int mid){ memset(dp,0,sizeof(dp)); queue<int> small,large; for(int i = 1; i<=n; ++i){ while(!small.empty()&&a[i]-a[small.front()]+1>mid) small.pop(); while(!large.empty()&&a[i]-a[large.front()]+1>mid<<1) large.pop(); dp[i][0]=dp[Front(i,large)-1][0]+1; for(int j = 1; j<=p; ++j) dp[i][j]=min(dp[Front(i,small)-1][j-1],dp[Front(i,large)-1][j]+1); small.push(i), large.push(i); } return dp[n][p]<=q; } int bs(int l, int r){ int rs=1; while(l<=r){ int mid=(l+r)>>1; if(check(mid)) rs=mid, r=mid-1; else l=mid+1; } return rs; } int main() { tt; if(fopen((NAME + ".INP").c_str(), "r")) fo; cin >> n >> p >> q; for(int i = 1; i<=n; ++i) cin >> a[i]; if(p+q>=n){ cout << 1; return 0; } sort(a+1,a+n+1); cout << bs(1,1e9); }

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:55:45: note: in expansion of macro 'fo'
   55 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
watching.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:55:45: note: in expansion of macro 'fo'
   55 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...