# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
405588 |
2021-05-16T14:54:37 Z |
sad |
Cigle (COI21_cigle) |
C++14 |
|
6 ms |
6360 KB |
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
int n;const int N=5100,M=500*5009;
pair<int,int>dp[N][N];int a[N],prf[M];
pair<int,int>mxdp[N][N];
vector<int>v;
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;int ans=0;int rw=0;
for(int i=1;i<n+1;i++)cin>>a[i];
for(int m=1;m<=n;m++)
{
for(auto it:v)prf[it]=-1;
v.clear();
int re=0;v.pb(0);
for(int i=m;i>0;i--)
{
re+=a[i];v.pb(re);
prf[re]=i;
}
re=0;
dp[m][m]={0,n+1};
mxdp[m][1]={dp[m][1].fi,1};
for(int i=2;i<m;i++)
{
if(dp[m][i].fi>mxdp[m][i-1].fi)
{
mxdp[m][i]={dp[m][i].fi,i};continue;
}
mxdp[m][i]=mxdp[m][i-1];
}
dp[m+1][m]=mxdp[m][m-1];ans=max(ans,dp[m+1][m].fi);
rw=0;
for(int r=m+2;r<n+1;r++)
{re+=a[r-1];
if(prf[re]!=-1)rw++;
int last=dp[r-1][m].se;
int mx=dp[r-1][m].fi;
if(prf[re]==-1||prf[re]-2<0)
{
dp[r][m]=dp[r-1][m];
ans=max(ans,mx);continue;
}
pair<int,int>z=mxdp[m][prf[re]-2];
z.fi+=rw;
if(z.fi>mx)
{
dp[r][m]=z;
ans=max(ans,z.fi);continue;
}
dp[r][m]=dp[r-1][m];
ans=max(ans,mx);
continue;
}
}
cout<<ans;
}
/*
10
2 3 2 1 1 5 5 2 5 1
*/
Compilation message
cigle.cpp: In function 'int main()':
cigle.cpp:42:17: warning: unused variable 'last' [-Wunused-variable]
42 | int last=dp[r-1][m].se;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
6348 KB |
Output is correct |
2 |
Correct |
6 ms |
6348 KB |
Output is correct |
3 |
Correct |
6 ms |
6360 KB |
Output is correct |
4 |
Correct |
5 ms |
6348 KB |
Output is correct |
5 |
Correct |
5 ms |
6348 KB |
Output is correct |
6 |
Correct |
6 ms |
6348 KB |
Output is correct |
7 |
Correct |
6 ms |
6348 KB |
Output is correct |
8 |
Correct |
6 ms |
6348 KB |
Output is correct |
9 |
Correct |
6 ms |
6348 KB |
Output is correct |
10 |
Correct |
5 ms |
6348 KB |
Output is correct |
11 |
Correct |
5 ms |
6304 KB |
Output is correct |
12 |
Incorrect |
5 ms |
6348 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
588 KB |
Output is correct |
8 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |