# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
645578 |
2022-09-27T11:17:32 Z |
Pety |
Cigle (COI21_cigle) |
C++14 |
|
2 ms |
2768 KB |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int dp[5002][5002], sum[5002], n, pref[5002];
int main ()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
sum[i] = sum[i - 1] + a;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++)
pref[j] = max(pref[j - 1], dp[j][i - 1]);
int matches = 0;
int ind = i - 1, best = pref[i - 1];
for (int j = i; j <= n; j++) {
dp[i][j] = best;
while (ind > 0 && sum[j] - sum[i - 1] > sum[i - 1] - sum[ind])
ind--;
if (ind && sum[j] - sum[i - 1] == sum[i - 1] - sum[ind]) {
matches++;
best = max(best, matches + pref[ind - 1]);
}
}
}
int mx = 0;
for (int i = 1; i <= n; i++)
mx = max(mx, dp[i][n]);
cout << mx+1 << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |