Submission #886690

#TimeUsernameProblemLanguageResultExecution timeMemory
886690AgentPenginWatching (JOI13_watching)C++14
100 / 100
332 ms31860 KiB
/** * author: AgentPengin ( Độc cô cầu bại ) * created: 23.12.2022 10:08:02 * too lazy to update time **/ #include<bits/stdc++.h> #define EL '\n' #define fi first #define se second #define NAME "TASK" #define ll long long #define lcm(a,b) (a/gcd(a,b))*b #define db(val) "["#val" = " << (val) << "] " #define bend(v) (v).begin(),(v).end() #define sz(v) (int)(v).size() #define ex exit(0) using namespace std; const ll mod = 1e9 + 7; const int inf = 0x1FFFFFFF; const int MAXN = 2005; int n,P,Q,a[MAXN]; pair<int,int> dp[MAXN][MAXN]; inline void maximize(pair<int,int>& u,const pair<int,int> v) { if (v.fi < u.fi) u = v; else if (v.fi == u.fi && v.se > u.se) u = v; } bool check(int mid) { // dp[i] = {P,Q} -> uu tien su dung P truoc Q sau // dp[i][j] -> the first i-th, use j type 1, fi type 2, go second for (int i = 1;i <= n;i++) { for (int j = 0;j <= P;j++) dp[i][j] = make_pair(inf,0); } dp[1][0] = make_pair(1,2 * mid - 1); dp[1][1] = make_pair(0,mid - 1); for (int i = 1;i < n;i++) { for (int j = 0;j <= P;j++) { if (a[i + 1] - a[i] <= dp[i][j].se) { maximize(dp[i + 1][j],make_pair(dp[i][j].fi,dp[i][j].se - (a[i + 1] - a[i]))); } if (j < P) maximize(dp[i + 1][j + 1],make_pair(dp[i][j].fi,mid - 1)); maximize(dp[i + 1][j],make_pair(dp[i][j].fi + 1,2 * mid - 1)); } } for (int j = 0;j <= P;j++) { if (dp[n][j].fi <= Q) return true; } return false; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); if (ifstream(NAME".inp")) { freopen(NAME".inp","r",stdin); freopen(NAME".out","w",stdout); } cin >> n >> P >> Q; if (P + Q >= n) return cout << 1,0; for (int i = 1;i <= n;i++) cin >> a[i]; sort(a + 1,a + n + 1); int l = 1,r = 1e9,ans = 1e9; while(l <= r) { int mid = l + r >> 1; if (check(mid)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; } // agent pengin wants to take apio (with anya-san)

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:72:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |   int mid = l + r >> 1;
      |             ~~^~~
watching.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(NAME".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
watching.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(NAME".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...