# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1003535 |
2024-06-20T12:32:26 Z |
teesla |
Cigle (COI21_cigle) |
C++14 |
|
30 ms |
1372 KB |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> tam(n+1, 0);
vector<int> sum(n+1, 0);
for(int i=1; i<=n; i++) cin >> tam[i];
for(int i=1; i<=n; i++) sum[i] = sum[i-1] + tam[i];
vector<vector<int>> dp(n+1, vector<int> (n+1,0));
int maior = 0;
for(int l = 1; l<= n; l++) for(int r = l; r<=n; r++){
int qnt = 0;
int cima = l, baixo = l-1;
int SumCima = tam[l];
int SumBaixo = tam[l-1];
dp[l][r] = max(dp[l][r], dp[l-1][l-1]);
while(cima < r and baixo >0){
if(SumCima == SumBaixo) {
qnt++;
baixo--;
cima++;
SumBaixo+= tam[baixo];
SumCima+= tam[cima];
dp[l][r] = max(dp[l][r], dp[baixo][l-1] + qnt);
}
else if(SumCima > SumBaixo) {baixo--; SumBaixo+= tam[baixo]; dp[l][r] = max(dp[l][r], dp[baixo][l-1] + qnt);}
else{ cima++; SumCima += tam[cima]; dp[l][r] = max(dp[l][r], dp[baixo][l-1] + qnt);}
}
//cout << l << ' '<< r << ' '<< qnt << endl;
for(int oo = baixo; oo>=1; oo--){
dp[l][r] = max(dp[l][r], dp[oo][l-1] + qnt);
}
maior = max(maior, dp[l][r]);
}
// for(int i=1; i<=n; i++){
// for(int j=1; j<=n; j++) cout << dp[i][j] << ' ';
// cout << endl;
// }
cout << maior << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
1368 KB |
Output is correct |
2 |
Incorrect |
30 ms |
1372 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |