#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
int32_t main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n, tot, cnt, ans = 0; cin >> n;
int arr[n], pref[n], dp[n][n];
for (int i = 0; i < n; i++) fill(dp[i], dp[i] + n, 0);
for (int i = 0; i < n; i++) cin >> arr[i];
for (int s = 0; s < n; s++){
for (int e = s; e < n; e++){
if (s == 0) dp[s][e] = 0;
else{
set <int> se; tot = arr[s]; cnt = 0;
for (int i = s + 1; i <= e; i++){
se.insert(tot);
tot += arr[i];
}
tot = 0;
for (int i = s - 1; i >= 0; i--){
dp[s][e] = max(dp[s][e], dp[i][s - 1] + cnt);
tot += arr[i];
if (se.find(tot) != se.end()) cnt += 1;
}
}
}
}
for (int i = 0; i < n; i++) ans = max(ans, dp[i][n - 1]);
cout << ans;
}
Compilation message
cigle.cpp: In function 'int32_t main()':
cigle.cpp:12:14: warning: unused variable 'pref' [-Wunused-variable]
12 | int arr[n], pref[n], dp[n][n];
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
5 ms |
340 KB |
Output is correct |
12 |
Correct |
6 ms |
372 KB |
Output is correct |
13 |
Correct |
6 ms |
316 KB |
Output is correct |
14 |
Correct |
5 ms |
320 KB |
Output is correct |
15 |
Correct |
5 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
340 KB |
Output is correct |
17 |
Correct |
5 ms |
316 KB |
Output is correct |
18 |
Correct |
5 ms |
372 KB |
Output is correct |
19 |
Correct |
5 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1070 ms |
2260 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
5 ms |
340 KB |
Output is correct |
12 |
Correct |
6 ms |
372 KB |
Output is correct |
13 |
Correct |
6 ms |
316 KB |
Output is correct |
14 |
Correct |
5 ms |
320 KB |
Output is correct |
15 |
Correct |
5 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
340 KB |
Output is correct |
17 |
Correct |
5 ms |
316 KB |
Output is correct |
18 |
Correct |
5 ms |
372 KB |
Output is correct |
19 |
Correct |
5 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
316 KB |
Output is correct |
21 |
Execution timed out |
1070 ms |
2260 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
5 ms |
340 KB |
Output is correct |
11 |
Correct |
5 ms |
340 KB |
Output is correct |
12 |
Correct |
6 ms |
372 KB |
Output is correct |
13 |
Correct |
6 ms |
316 KB |
Output is correct |
14 |
Correct |
5 ms |
320 KB |
Output is correct |
15 |
Correct |
5 ms |
340 KB |
Output is correct |
16 |
Correct |
5 ms |
340 KB |
Output is correct |
17 |
Correct |
5 ms |
316 KB |
Output is correct |
18 |
Correct |
5 ms |
372 KB |
Output is correct |
19 |
Correct |
5 ms |
340 KB |
Output is correct |
20 |
Correct |
5 ms |
316 KB |
Output is correct |
21 |
Execution timed out |
1070 ms |
2260 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |