# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1116203 |
2024-11-21T10:43:01 Z |
NotLinux |
Cigle (COI21_cigle) |
C++17 |
|
508 ms |
294300 KB |
// Author : FatihCihan
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin() , v.end()
#define sz(a) (int)a.size()
const int N = 5e3 * 5e3 + 7;
const int inf = 1e9 + 7;
void solve(){
int n;
cin >> n;
int arr[n] , pre[n+1] , cnt[N];
memset(cnt , -1 , sizeof(cnt));
pre[0] = 0;
cnt[0] = -1;
for(int i = 0;i<n;i++){
cin >> arr[i];
pre[i+1] = pre[i] + arr[i];
cnt[pre[i+1]] = i;
}
int dp[n+1][n+1] = {0} , maxi[n+1][n+1] = {0};
for(int j = 2;j<n;j++){
int sayac = 0;
for(int i = j+1;i<=n;i++){
maxi[i][j] = max({maxi[i][j] , maxi[i-1][j] , maxi[i][j-1] , dp[i][j]});
if(2 * pre[j] - pre[i] >= 0 and cnt[2 * pre[j] - pre[i]] != -1){
sayac++;
// cout << " aha : " << i << " , " << j << " => " << sayac << " + " << maxi[j][cnt[2 * pre[j] - pre[i]]] << endl;
// cout << "wtf : " << j << " , " << cnt[2 * pre[j] - pre[i]] << " : " << maxi[j][cnt[2 * pre[j] - pre[i]]] << endl;
dp[i+1][j] = max(dp[i+1][j] , maxi[j][cnt[2 * pre[j] - pre[i]]] + sayac);
// cout << "AHA : " << i << " , " << j << " : " << maxi[j][cnt[2 * pre[j] - pre[i]]] << " tf " << cnt[2 * pre[j] - pre[i]] << endl;
}
else{
dp[i+1][j] = max(dp[i+1][j] , dp[i][j]);
}
if(j > 0){
if(i - j > 1)dp[i+1][i] = max(dp[i+1][i] , dp[i][j]);
}
else{
if(i > 2)dp[i+1][i] = max(dp[i+1][i] , dp[i][j]);
}
// if(dp[i][j] >= 3){
// cout << i << " " << j << " : " << dp[i][j] << " , " << maxi[i][j] << endl;
// }
}
}
int ans = 0;
for(int i = 0;i<n;i++){
ans = max(ans , dp[n][i]);
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
cerr << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
98120 KB |
Output is correct |
2 |
Correct |
84 ms |
98120 KB |
Output is correct |
3 |
Correct |
86 ms |
98048 KB |
Output is correct |
4 |
Correct |
92 ms |
98120 KB |
Output is correct |
5 |
Correct |
81 ms |
98120 KB |
Output is correct |
6 |
Correct |
75 ms |
98184 KB |
Output is correct |
7 |
Correct |
83 ms |
98120 KB |
Output is correct |
8 |
Correct |
83 ms |
98120 KB |
Output is correct |
9 |
Correct |
87 ms |
98272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
98120 KB |
Output is correct |
2 |
Correct |
84 ms |
98120 KB |
Output is correct |
3 |
Correct |
86 ms |
98048 KB |
Output is correct |
4 |
Correct |
92 ms |
98120 KB |
Output is correct |
5 |
Correct |
81 ms |
98120 KB |
Output is correct |
6 |
Correct |
75 ms |
98184 KB |
Output is correct |
7 |
Correct |
83 ms |
98120 KB |
Output is correct |
8 |
Correct |
83 ms |
98120 KB |
Output is correct |
9 |
Correct |
87 ms |
98272 KB |
Output is correct |
10 |
Correct |
85 ms |
98120 KB |
Output is correct |
11 |
Correct |
83 ms |
98120 KB |
Output is correct |
12 |
Correct |
84 ms |
98132 KB |
Output is correct |
13 |
Correct |
82 ms |
98120 KB |
Output is correct |
14 |
Correct |
87 ms |
98120 KB |
Output is correct |
15 |
Correct |
79 ms |
98120 KB |
Output is correct |
16 |
Correct |
83 ms |
98128 KB |
Output is correct |
17 |
Correct |
86 ms |
98120 KB |
Output is correct |
18 |
Correct |
83 ms |
98120 KB |
Output is correct |
19 |
Correct |
82 ms |
98120 KB |
Output is correct |
20 |
Correct |
82 ms |
98120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
100132 KB |
Output is correct |
2 |
Correct |
88 ms |
100172 KB |
Output is correct |
3 |
Correct |
86 ms |
100168 KB |
Output is correct |
4 |
Correct |
86 ms |
100168 KB |
Output is correct |
5 |
Correct |
86 ms |
100168 KB |
Output is correct |
6 |
Correct |
88 ms |
100168 KB |
Output is correct |
7 |
Correct |
95 ms |
100184 KB |
Output is correct |
8 |
Correct |
80 ms |
100168 KB |
Output is correct |
9 |
Correct |
83 ms |
100168 KB |
Output is correct |
10 |
Correct |
80 ms |
100216 KB |
Output is correct |
11 |
Correct |
80 ms |
100168 KB |
Output is correct |
12 |
Correct |
80 ms |
100168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
98120 KB |
Output is correct |
2 |
Correct |
84 ms |
98120 KB |
Output is correct |
3 |
Correct |
86 ms |
98048 KB |
Output is correct |
4 |
Correct |
92 ms |
98120 KB |
Output is correct |
5 |
Correct |
81 ms |
98120 KB |
Output is correct |
6 |
Correct |
75 ms |
98184 KB |
Output is correct |
7 |
Correct |
83 ms |
98120 KB |
Output is correct |
8 |
Correct |
83 ms |
98120 KB |
Output is correct |
9 |
Correct |
87 ms |
98272 KB |
Output is correct |
10 |
Correct |
85 ms |
98120 KB |
Output is correct |
11 |
Correct |
83 ms |
98120 KB |
Output is correct |
12 |
Correct |
84 ms |
98132 KB |
Output is correct |
13 |
Correct |
82 ms |
98120 KB |
Output is correct |
14 |
Correct |
87 ms |
98120 KB |
Output is correct |
15 |
Correct |
79 ms |
98120 KB |
Output is correct |
16 |
Correct |
83 ms |
98128 KB |
Output is correct |
17 |
Correct |
86 ms |
98120 KB |
Output is correct |
18 |
Correct |
83 ms |
98120 KB |
Output is correct |
19 |
Correct |
82 ms |
98120 KB |
Output is correct |
20 |
Correct |
82 ms |
98120 KB |
Output is correct |
21 |
Correct |
80 ms |
100132 KB |
Output is correct |
22 |
Correct |
88 ms |
100172 KB |
Output is correct |
23 |
Correct |
86 ms |
100168 KB |
Output is correct |
24 |
Correct |
86 ms |
100168 KB |
Output is correct |
25 |
Correct |
86 ms |
100168 KB |
Output is correct |
26 |
Correct |
88 ms |
100168 KB |
Output is correct |
27 |
Correct |
95 ms |
100184 KB |
Output is correct |
28 |
Correct |
80 ms |
100168 KB |
Output is correct |
29 |
Correct |
83 ms |
100168 KB |
Output is correct |
30 |
Correct |
80 ms |
100216 KB |
Output is correct |
31 |
Correct |
80 ms |
100168 KB |
Output is correct |
32 |
Correct |
80 ms |
100168 KB |
Output is correct |
33 |
Correct |
88 ms |
100168 KB |
Output is correct |
34 |
Correct |
87 ms |
100084 KB |
Output is correct |
35 |
Correct |
90 ms |
100168 KB |
Output is correct |
36 |
Correct |
83 ms |
100104 KB |
Output is correct |
37 |
Correct |
83 ms |
100168 KB |
Output is correct |
38 |
Correct |
92 ms |
100168 KB |
Output is correct |
39 |
Correct |
80 ms |
100100 KB |
Output is correct |
40 |
Correct |
87 ms |
100184 KB |
Output is correct |
41 |
Correct |
88 ms |
100168 KB |
Output is correct |
42 |
Correct |
89 ms |
100168 KB |
Output is correct |
43 |
Correct |
89 ms |
100152 KB |
Output is correct |
44 |
Correct |
86 ms |
100168 KB |
Output is correct |
45 |
Correct |
90 ms |
100168 KB |
Output is correct |
46 |
Correct |
84 ms |
100244 KB |
Output is correct |
47 |
Correct |
88 ms |
100168 KB |
Output is correct |
48 |
Correct |
90 ms |
100168 KB |
Output is correct |
49 |
Correct |
87 ms |
100168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
98120 KB |
Output is correct |
2 |
Correct |
84 ms |
98120 KB |
Output is correct |
3 |
Correct |
86 ms |
98048 KB |
Output is correct |
4 |
Correct |
92 ms |
98120 KB |
Output is correct |
5 |
Correct |
81 ms |
98120 KB |
Output is correct |
6 |
Correct |
75 ms |
98184 KB |
Output is correct |
7 |
Correct |
83 ms |
98120 KB |
Output is correct |
8 |
Correct |
83 ms |
98120 KB |
Output is correct |
9 |
Correct |
87 ms |
98272 KB |
Output is correct |
10 |
Correct |
85 ms |
98120 KB |
Output is correct |
11 |
Correct |
83 ms |
98120 KB |
Output is correct |
12 |
Correct |
84 ms |
98132 KB |
Output is correct |
13 |
Correct |
82 ms |
98120 KB |
Output is correct |
14 |
Correct |
87 ms |
98120 KB |
Output is correct |
15 |
Correct |
79 ms |
98120 KB |
Output is correct |
16 |
Correct |
83 ms |
98128 KB |
Output is correct |
17 |
Correct |
86 ms |
98120 KB |
Output is correct |
18 |
Correct |
83 ms |
98120 KB |
Output is correct |
19 |
Correct |
82 ms |
98120 KB |
Output is correct |
20 |
Correct |
82 ms |
98120 KB |
Output is correct |
21 |
Correct |
80 ms |
100132 KB |
Output is correct |
22 |
Correct |
88 ms |
100172 KB |
Output is correct |
23 |
Correct |
86 ms |
100168 KB |
Output is correct |
24 |
Correct |
86 ms |
100168 KB |
Output is correct |
25 |
Correct |
86 ms |
100168 KB |
Output is correct |
26 |
Correct |
88 ms |
100168 KB |
Output is correct |
27 |
Correct |
95 ms |
100184 KB |
Output is correct |
28 |
Correct |
80 ms |
100168 KB |
Output is correct |
29 |
Correct |
83 ms |
100168 KB |
Output is correct |
30 |
Correct |
80 ms |
100216 KB |
Output is correct |
31 |
Correct |
80 ms |
100168 KB |
Output is correct |
32 |
Correct |
80 ms |
100168 KB |
Output is correct |
33 |
Correct |
88 ms |
100168 KB |
Output is correct |
34 |
Correct |
87 ms |
100084 KB |
Output is correct |
35 |
Correct |
90 ms |
100168 KB |
Output is correct |
36 |
Correct |
83 ms |
100104 KB |
Output is correct |
37 |
Correct |
83 ms |
100168 KB |
Output is correct |
38 |
Correct |
92 ms |
100168 KB |
Output is correct |
39 |
Correct |
80 ms |
100100 KB |
Output is correct |
40 |
Correct |
87 ms |
100184 KB |
Output is correct |
41 |
Correct |
88 ms |
100168 KB |
Output is correct |
42 |
Correct |
89 ms |
100168 KB |
Output is correct |
43 |
Correct |
89 ms |
100152 KB |
Output is correct |
44 |
Correct |
86 ms |
100168 KB |
Output is correct |
45 |
Correct |
90 ms |
100168 KB |
Output is correct |
46 |
Correct |
84 ms |
100244 KB |
Output is correct |
47 |
Correct |
88 ms |
100168 KB |
Output is correct |
48 |
Correct |
90 ms |
100168 KB |
Output is correct |
49 |
Correct |
87 ms |
100168 KB |
Output is correct |
50 |
Correct |
470 ms |
294100 KB |
Output is correct |
51 |
Correct |
415 ms |
294076 KB |
Output is correct |
52 |
Correct |
432 ms |
293960 KB |
Output is correct |
53 |
Correct |
412 ms |
294024 KB |
Output is correct |
54 |
Correct |
455 ms |
293900 KB |
Output is correct |
55 |
Correct |
452 ms |
293960 KB |
Output is correct |
56 |
Correct |
430 ms |
293960 KB |
Output is correct |
57 |
Correct |
440 ms |
294300 KB |
Output is correct |
58 |
Correct |
419 ms |
293996 KB |
Output is correct |
59 |
Correct |
416 ms |
293956 KB |
Output is correct |
60 |
Correct |
508 ms |
293960 KB |
Output is correct |
61 |
Correct |
451 ms |
293960 KB |
Output is correct |
62 |
Correct |
440 ms |
293960 KB |
Output is correct |
63 |
Correct |
419 ms |
293960 KB |
Output is correct |
64 |
Correct |
427 ms |
293960 KB |
Output is correct |
65 |
Correct |
438 ms |
294012 KB |
Output is correct |
66 |
Correct |
435 ms |
294124 KB |
Output is correct |
67 |
Correct |
401 ms |
293960 KB |
Output is correct |
68 |
Correct |
422 ms |
294040 KB |
Output is correct |
69 |
Correct |
408 ms |
293992 KB |
Output is correct |
70 |
Correct |
485 ms |
293960 KB |
Output is correct |
71 |
Correct |
453 ms |
294124 KB |
Output is correct |
72 |
Correct |
440 ms |
294120 KB |
Output is correct |