Submission #706649

# Submission time Handle Problem Language Result Execution time Memory
706649 2023-03-07T09:34:16 Z ld_minh4354 Cigle (COI21_cigle) C++17
100 / 100
251 ms 392708 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"



signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//	freopen("input.000","r",stdin);
//	freopen("output.000","w",stdout);
//	srand((unsigned)time(NULL));
//	rand()
	
	int n,i,a[5005],dp[5005][5005],j,cnt,l,diff,optl,ans,dpmax[5005][5005];
	
	cin>>n;
	for (i=1;i<n+1;i++) cin>>a[i];
	
	for (j=1;j<n+1;j++) dp[0][j]=dp[1][j]=0;
	for (j=1;j<n+1;j++) dpmax[0][j]=dpmax[1][j]=0;
	
	ans=0;
	for (i=2;i<n;i++)
	{
		cnt=0;l=i-1;diff=0;optl=i-1;
		
		dp[i][i+1]=dpmax[i-1][i];
		dpmax[i][i+1]=max(dpmax[i-1][i+1],dp[i][i+1]);
		
		for (j=i+2;j<n+1;j++)
		{
			diff -= a[j-1];
			while (diff<0 and l>0)
			{
				diff += a[l+1];
				l--;
			}
			
			if (diff==0)
			{
				cnt++;
				optl=l;
			}
			
			dp[i][j]=max(dp[i][j-1],dpmax[optl][i]+cnt);
			dpmax[i][j]=max(dpmax[i-1][j],dp[i][j]);
			
			ans=max(ans,dp[i][j]);
//			cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<optl<<" "<<cnt<<"\n";
		}
	}
	
	cout<<ans;
}

# Verdict Execution time Memory Grader output
1 Correct 147 ms 392624 KB Output is correct
2 Correct 155 ms 392504 KB Output is correct
3 Correct 247 ms 392428 KB Output is correct
4 Correct 150 ms 392424 KB Output is correct
5 Correct 160 ms 392420 KB Output is correct
6 Correct 168 ms 392448 KB Output is correct
7 Correct 156 ms 392400 KB Output is correct
8 Correct 153 ms 392516 KB Output is correct
9 Correct 150 ms 392396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 392624 KB Output is correct
2 Correct 155 ms 392504 KB Output is correct
3 Correct 247 ms 392428 KB Output is correct
4 Correct 150 ms 392424 KB Output is correct
5 Correct 160 ms 392420 KB Output is correct
6 Correct 168 ms 392448 KB Output is correct
7 Correct 156 ms 392400 KB Output is correct
8 Correct 153 ms 392516 KB Output is correct
9 Correct 150 ms 392396 KB Output is correct
10 Correct 149 ms 392592 KB Output is correct
11 Correct 151 ms 392476 KB Output is correct
12 Correct 151 ms 392420 KB Output is correct
13 Correct 153 ms 392468 KB Output is correct
14 Correct 150 ms 392396 KB Output is correct
15 Correct 157 ms 392692 KB Output is correct
16 Correct 151 ms 392396 KB Output is correct
17 Correct 152 ms 392484 KB Output is correct
18 Correct 149 ms 392532 KB Output is correct
19 Correct 156 ms 392532 KB Output is correct
20 Correct 148 ms 392396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 392416 KB Output is correct
2 Correct 151 ms 392504 KB Output is correct
3 Correct 153 ms 392524 KB Output is correct
4 Correct 153 ms 392508 KB Output is correct
5 Correct 149 ms 392396 KB Output is correct
6 Correct 150 ms 392404 KB Output is correct
7 Correct 152 ms 392408 KB Output is correct
8 Correct 150 ms 392436 KB Output is correct
9 Correct 152 ms 392392 KB Output is correct
10 Correct 151 ms 392544 KB Output is correct
11 Correct 152 ms 392472 KB Output is correct
12 Correct 150 ms 392448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 392624 KB Output is correct
2 Correct 155 ms 392504 KB Output is correct
3 Correct 247 ms 392428 KB Output is correct
4 Correct 150 ms 392424 KB Output is correct
5 Correct 160 ms 392420 KB Output is correct
6 Correct 168 ms 392448 KB Output is correct
7 Correct 156 ms 392400 KB Output is correct
8 Correct 153 ms 392516 KB Output is correct
9 Correct 150 ms 392396 KB Output is correct
10 Correct 149 ms 392592 KB Output is correct
11 Correct 151 ms 392476 KB Output is correct
12 Correct 151 ms 392420 KB Output is correct
13 Correct 153 ms 392468 KB Output is correct
14 Correct 150 ms 392396 KB Output is correct
15 Correct 157 ms 392692 KB Output is correct
16 Correct 151 ms 392396 KB Output is correct
17 Correct 152 ms 392484 KB Output is correct
18 Correct 149 ms 392532 KB Output is correct
19 Correct 156 ms 392532 KB Output is correct
20 Correct 148 ms 392396 KB Output is correct
21 Correct 147 ms 392416 KB Output is correct
22 Correct 151 ms 392504 KB Output is correct
23 Correct 153 ms 392524 KB Output is correct
24 Correct 153 ms 392508 KB Output is correct
25 Correct 149 ms 392396 KB Output is correct
26 Correct 150 ms 392404 KB Output is correct
27 Correct 152 ms 392408 KB Output is correct
28 Correct 150 ms 392436 KB Output is correct
29 Correct 152 ms 392392 KB Output is correct
30 Correct 151 ms 392544 KB Output is correct
31 Correct 152 ms 392472 KB Output is correct
32 Correct 150 ms 392448 KB Output is correct
33 Correct 151 ms 392480 KB Output is correct
34 Correct 148 ms 392440 KB Output is correct
35 Correct 148 ms 392532 KB Output is correct
36 Correct 147 ms 392396 KB Output is correct
37 Correct 156 ms 392472 KB Output is correct
38 Correct 159 ms 392432 KB Output is correct
39 Correct 151 ms 392652 KB Output is correct
40 Correct 156 ms 392396 KB Output is correct
41 Correct 147 ms 392568 KB Output is correct
42 Correct 149 ms 392444 KB Output is correct
43 Correct 150 ms 392564 KB Output is correct
44 Correct 149 ms 392416 KB Output is correct
45 Correct 150 ms 392396 KB Output is correct
46 Correct 151 ms 392488 KB Output is correct
47 Correct 153 ms 392396 KB Output is correct
48 Correct 148 ms 392488 KB Output is correct
49 Correct 147 ms 392392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 147 ms 392624 KB Output is correct
2 Correct 155 ms 392504 KB Output is correct
3 Correct 247 ms 392428 KB Output is correct
4 Correct 150 ms 392424 KB Output is correct
5 Correct 160 ms 392420 KB Output is correct
6 Correct 168 ms 392448 KB Output is correct
7 Correct 156 ms 392400 KB Output is correct
8 Correct 153 ms 392516 KB Output is correct
9 Correct 150 ms 392396 KB Output is correct
10 Correct 149 ms 392592 KB Output is correct
11 Correct 151 ms 392476 KB Output is correct
12 Correct 151 ms 392420 KB Output is correct
13 Correct 153 ms 392468 KB Output is correct
14 Correct 150 ms 392396 KB Output is correct
15 Correct 157 ms 392692 KB Output is correct
16 Correct 151 ms 392396 KB Output is correct
17 Correct 152 ms 392484 KB Output is correct
18 Correct 149 ms 392532 KB Output is correct
19 Correct 156 ms 392532 KB Output is correct
20 Correct 148 ms 392396 KB Output is correct
21 Correct 147 ms 392416 KB Output is correct
22 Correct 151 ms 392504 KB Output is correct
23 Correct 153 ms 392524 KB Output is correct
24 Correct 153 ms 392508 KB Output is correct
25 Correct 149 ms 392396 KB Output is correct
26 Correct 150 ms 392404 KB Output is correct
27 Correct 152 ms 392408 KB Output is correct
28 Correct 150 ms 392436 KB Output is correct
29 Correct 152 ms 392392 KB Output is correct
30 Correct 151 ms 392544 KB Output is correct
31 Correct 152 ms 392472 KB Output is correct
32 Correct 150 ms 392448 KB Output is correct
33 Correct 151 ms 392480 KB Output is correct
34 Correct 148 ms 392440 KB Output is correct
35 Correct 148 ms 392532 KB Output is correct
36 Correct 147 ms 392396 KB Output is correct
37 Correct 156 ms 392472 KB Output is correct
38 Correct 159 ms 392432 KB Output is correct
39 Correct 151 ms 392652 KB Output is correct
40 Correct 156 ms 392396 KB Output is correct
41 Correct 147 ms 392568 KB Output is correct
42 Correct 149 ms 392444 KB Output is correct
43 Correct 150 ms 392564 KB Output is correct
44 Correct 149 ms 392416 KB Output is correct
45 Correct 150 ms 392396 KB Output is correct
46 Correct 151 ms 392488 KB Output is correct
47 Correct 153 ms 392396 KB Output is correct
48 Correct 148 ms 392488 KB Output is correct
49 Correct 147 ms 392392 KB Output is correct
50 Correct 218 ms 392396 KB Output is correct
51 Correct 217 ms 392432 KB Output is correct
52 Correct 216 ms 392512 KB Output is correct
53 Correct 223 ms 392520 KB Output is correct
54 Correct 221 ms 392480 KB Output is correct
55 Correct 251 ms 392520 KB Output is correct
56 Correct 237 ms 392520 KB Output is correct
57 Correct 235 ms 392708 KB Output is correct
58 Correct 235 ms 392396 KB Output is correct
59 Correct 235 ms 392520 KB Output is correct
60 Correct 220 ms 392620 KB Output is correct
61 Correct 203 ms 392524 KB Output is correct
62 Correct 198 ms 392600 KB Output is correct
63 Correct 195 ms 392500 KB Output is correct
64 Correct 197 ms 392488 KB Output is correct
65 Correct 196 ms 392524 KB Output is correct
66 Correct 200 ms 392660 KB Output is correct
67 Correct 188 ms 392524 KB Output is correct
68 Correct 190 ms 392520 KB Output is correct
69 Correct 193 ms 392456 KB Output is correct
70 Correct 211 ms 392528 KB Output is correct
71 Correct 230 ms 392624 KB Output is correct
72 Correct 216 ms 392552 KB Output is correct