# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
971702 |
2024-04-29T07:59:03 Z |
LucaIlie |
Cigle (COI21_cigle) |
C++17 |
|
2 ms |
2908 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 5000;
int d[MAX_N + 1], sd[MAX_N + 1], dp[MAX_N + 1][MAX_N + 1];
int main() {
int n;
cin >> n;
for ( int i = 1; i <= n; i++ ) {
cin >> d[i];
sd[i] = sd[i - 1] + d[i];
}
for ( int i = 1; i <= n; i++ ) {
int k = i, lk = i + 1, c = 0;
for ( int j = i + 1; j <= n; j++ ) {
while ( k > 0 && sd[i] - sd[k] < sd[j] - sd[i] )
k--;
//printf( "%d %d %d %d\n", k, i, j, sd[j] - sd[i] );
dp[i][j] = max( dp[i][j], dp[k][i] + c - (k == lk) );
if ( sd[i] - sd[k] == sd[j] - sd[i] ) {
c++;
lk = k;
}
}
for ( int j = i; j <= n; j++ )
dp[i][j] = max( dp[i][j], max( dp[i - 1][j], dp[i][j - 1] ) );
}
/*for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j <= n; j++ )
printf( "%d ", dp[i][j] );
printf( "\n" );
}*/
int ans = 0;
for ( int i = 0; i <= n; i++ )
ans = max( ans, dp[i][n] );
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |