# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1116167 |
2024-11-21T09:50:35 Z |
NotLinux |
Cigle (COI21_cigle) |
C++17 |
|
91 ms |
100240 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++){
if(2 * pre[j] - pre[i] >= 0 and cnt[2 * pre[j] - pre[i]] != -1){
// cout << "aha : " << i << " , " << j << endl;
sayac++;
dp[i+1][j] = max(dp[i+1][j] , maxi[i-1][cnt[2 * pre[j] - pre[i]]] + sayac);
// cout << "AHA : " << i << " , " << j << " : " << maxi[i-1][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]);
}
maxi[i][j] = max(maxi[i][j-1] , 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]);
}
// cout << i << " " << j << " : " << dp[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 |
84 ms |
98200 KB |
Output is correct |
2 |
Incorrect |
78 ms |
98120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
98200 KB |
Output is correct |
2 |
Incorrect |
78 ms |
98120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
91 ms |
100240 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
98200 KB |
Output is correct |
2 |
Incorrect |
78 ms |
98120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
98200 KB |
Output is correct |
2 |
Incorrect |
78 ms |
98120 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |