# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1002899 |
2024-06-19T21:14:49 Z |
Lobo |
Cigle (COI21_cigle) |
C++17 |
|
262 ms |
197460 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
const int inf = 1e18+10;
int32_t main() {
// #ifndef ONLINE_JUDGE
// freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
// #endif
int n;
cin >> n;
vector<int> a(n+10);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<vector<int>> dp(n+10,vector<int>(n+10,-inf));
for(int i = 1; i <= n; i++) dp[1][i] = 0;
int ans = 0;
for(int i = 2; i <= n; i++) {
int k = i;
int sj = 0;
int sk = 0;
vector<int> qtd(n+10,0);
// cout << i << endl;
for(int j = i; j <= n; j++) {
sj+= a[j];
while(k-1 >= 1 && sk+a[k-1] <= sj) {
k--;
qtd[k] = (k == i-1 ? 0 : qtd[k+1]);
sk+= a[k];
if(sk == sj) qtd[k]++;
}
qtd[j] = (j == i ? 0 : qtd[j-1]);
if(sj == sk) qtd[j]++;
}
vector<int> pfmaxdp(n+10,-inf);
for(int j = 1; j <= i-1; j++) {
pfmaxdp[j] = max(pfmaxdp[j-1],dp[j][i-1]);
}
k = i;
sj = 0;
sk = 0;
int maxdpqtd = -inf;
for(int j = i; j <= n; j++) {
sj+= a[j];
while(k-1 >= 1 && sk+a[k-1] <= sj) {
k--;
sk+= a[k];
maxdpqtd = max(maxdpqtd,dp[k][i-1]+(k == i-1 ? 0 : qtd[k+1]));
}
maxdpqtd = max(maxdpqtd,dp[k][i-1]+(k == i-1 ? 0 : qtd[k+1]));
dp[i][j] = max(maxdpqtd,pfmaxdp[k-1]+(j == i ? 0 : qtd[j-1]));
// cout << " " << j << " " << k << " " << dp[i][j] << " " << dp[k][i-1] << endl;
}
}
for(int i = 1; i <= n; i++) {
ans = max(ans,dp[i][n]);
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
436 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
2 ms |
2484 KB |
Output is correct |
5 |
Correct |
3 ms |
2396 KB |
Output is correct |
6 |
Correct |
3 ms |
2500 KB |
Output is correct |
7 |
Correct |
3 ms |
2260 KB |
Output is correct |
8 |
Correct |
3 ms |
2392 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
2 ms |
2396 KB |
Output is correct |
12 |
Correct |
2 ms |
2504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
436 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2392 KB |
Output is correct |
23 |
Correct |
2 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2484 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2500 KB |
Output is correct |
27 |
Correct |
3 ms |
2260 KB |
Output is correct |
28 |
Correct |
3 ms |
2392 KB |
Output is correct |
29 |
Correct |
2 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2504 KB |
Output is correct |
33 |
Correct |
2 ms |
2392 KB |
Output is correct |
34 |
Correct |
2 ms |
2480 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
2 ms |
2396 KB |
Output is correct |
38 |
Correct |
2 ms |
2396 KB |
Output is correct |
39 |
Correct |
3 ms |
2396 KB |
Output is correct |
40 |
Correct |
3 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
2 ms |
2396 KB |
Output is correct |
43 |
Correct |
2 ms |
2396 KB |
Output is correct |
44 |
Correct |
2 ms |
2396 KB |
Output is correct |
45 |
Correct |
2 ms |
2484 KB |
Output is correct |
46 |
Correct |
2 ms |
2500 KB |
Output is correct |
47 |
Correct |
2 ms |
2396 KB |
Output is correct |
48 |
Correct |
4 ms |
2652 KB |
Output is correct |
49 |
Correct |
2 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
432 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
436 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
604 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2392 KB |
Output is correct |
23 |
Correct |
2 ms |
2396 KB |
Output is correct |
24 |
Correct |
2 ms |
2484 KB |
Output is correct |
25 |
Correct |
3 ms |
2396 KB |
Output is correct |
26 |
Correct |
3 ms |
2500 KB |
Output is correct |
27 |
Correct |
3 ms |
2260 KB |
Output is correct |
28 |
Correct |
3 ms |
2392 KB |
Output is correct |
29 |
Correct |
2 ms |
2396 KB |
Output is correct |
30 |
Correct |
2 ms |
2396 KB |
Output is correct |
31 |
Correct |
2 ms |
2396 KB |
Output is correct |
32 |
Correct |
2 ms |
2504 KB |
Output is correct |
33 |
Correct |
2 ms |
2392 KB |
Output is correct |
34 |
Correct |
2 ms |
2480 KB |
Output is correct |
35 |
Correct |
2 ms |
2396 KB |
Output is correct |
36 |
Correct |
2 ms |
2396 KB |
Output is correct |
37 |
Correct |
2 ms |
2396 KB |
Output is correct |
38 |
Correct |
2 ms |
2396 KB |
Output is correct |
39 |
Correct |
3 ms |
2396 KB |
Output is correct |
40 |
Correct |
3 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
2 ms |
2396 KB |
Output is correct |
43 |
Correct |
2 ms |
2396 KB |
Output is correct |
44 |
Correct |
2 ms |
2396 KB |
Output is correct |
45 |
Correct |
2 ms |
2484 KB |
Output is correct |
46 |
Correct |
2 ms |
2500 KB |
Output is correct |
47 |
Correct |
2 ms |
2396 KB |
Output is correct |
48 |
Correct |
4 ms |
2652 KB |
Output is correct |
49 |
Correct |
2 ms |
2396 KB |
Output is correct |
50 |
Correct |
222 ms |
197120 KB |
Output is correct |
51 |
Correct |
209 ms |
197204 KB |
Output is correct |
52 |
Correct |
185 ms |
197160 KB |
Output is correct |
53 |
Correct |
193 ms |
197200 KB |
Output is correct |
54 |
Correct |
199 ms |
197200 KB |
Output is correct |
55 |
Correct |
187 ms |
197180 KB |
Output is correct |
56 |
Correct |
217 ms |
197096 KB |
Output is correct |
57 |
Correct |
233 ms |
197052 KB |
Output is correct |
58 |
Correct |
243 ms |
197460 KB |
Output is correct |
59 |
Correct |
237 ms |
197176 KB |
Output is correct |
60 |
Correct |
241 ms |
197160 KB |
Output is correct |
61 |
Correct |
237 ms |
197200 KB |
Output is correct |
62 |
Correct |
222 ms |
197200 KB |
Output is correct |
63 |
Correct |
215 ms |
197200 KB |
Output is correct |
64 |
Correct |
226 ms |
197204 KB |
Output is correct |
65 |
Correct |
212 ms |
197112 KB |
Output is correct |
66 |
Correct |
211 ms |
197036 KB |
Output is correct |
67 |
Correct |
192 ms |
197188 KB |
Output is correct |
68 |
Correct |
196 ms |
197000 KB |
Output is correct |
69 |
Correct |
188 ms |
197220 KB |
Output is correct |
70 |
Correct |
234 ms |
197200 KB |
Output is correct |
71 |
Correct |
262 ms |
197444 KB |
Output is correct |
72 |
Correct |
244 ms |
197200 KB |
Output is correct |