Submission #961467

# Submission time Handle Problem Language Result Execution time Memory
961467 2024-04-12T07:07:57 Z ByeWorld Cigle (COI21_cigle) C++14
48 / 100
1000 ms 13416 KB
#include <bits/stdc++.h>
#include <random>
#define ll long long
#define int long long
#define fi first
#define se second
#define pb push_back
#define md ((l+r)>>1)
#define lf (id<<1)
#define rg ((id<<1)|1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,pii> ipii;
const int MAXN = 5e3+10;
const int MAXA = 1e6+10;
const int INF = 2e9+10;
const int LOG = 30;
const int MOD = 1e9+7;
void chmx(int &a, int b){
	a = max(a, b);
}

int n;
int a[MAXN], pr[MAXN], dp[MAXN][MAXN];

signed main() {
	// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		pr[i] = pr[i-1] + a[i];
	}
	for(int r=1; r<=n; r++){
		for(int k=r-1; k>=1; k--) chmx(dp[r][r], dp[k][r-1]);
		
		for(int l=1; l<=r-1; l++){
			// build dp[l][r], row atas

			dp[l][r] = dp[l][r-1];
			int down = 0, idx = l, add = 0;
			for(int k=l-1; k>=1; k--){
				// cek dp[k][l], row bawah
				chmx(dp[l][r], dp[k][l-1]+add);

				down += a[k];
				while(idx+1<=r-1 && pr[idx]-pr[l-1] < down){ // r gk boleh dipake
					// atas masi kurang
					idx++;
				} 
				if(pr[idx]-pr[l-1] == down) add++; // kena 4
			}
			if(dp[l][r]-dp[l][r-1] >= 2) assert(false);
		}
	}

	int ANS = 0;
	for(int i=1; i<=n; i++) ANS = max(ANS, dp[i][n]);
	cout << ANS << '\n';

	// dp[l][r] selalu increasing kalo r nya increasing?
	// for(int l=1; l<=n; l++){
	// 	for(int r=l; r<=n; r++) cout << dp[l][r] << "p\n"[r==n];
	// }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 3412 KB Output is correct
2 Correct 50 ms 3412 KB Output is correct
3 Correct 48 ms 3380 KB Output is correct
4 Correct 55 ms 3444 KB Output is correct
5 Correct 56 ms 3288 KB Output is correct
6 Correct 72 ms 3412 KB Output is correct
7 Correct 79 ms 3304 KB Output is correct
8 Correct 81 ms 3452 KB Output is correct
9 Correct 75 ms 3252 KB Output is correct
10 Correct 53 ms 3416 KB Output is correct
11 Correct 64 ms 3412 KB Output is correct
12 Correct 66 ms 3340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 49 ms 3412 KB Output is correct
22 Correct 50 ms 3412 KB Output is correct
23 Correct 48 ms 3380 KB Output is correct
24 Correct 55 ms 3444 KB Output is correct
25 Correct 56 ms 3288 KB Output is correct
26 Correct 72 ms 3412 KB Output is correct
27 Correct 79 ms 3304 KB Output is correct
28 Correct 81 ms 3452 KB Output is correct
29 Correct 75 ms 3252 KB Output is correct
30 Correct 53 ms 3416 KB Output is correct
31 Correct 64 ms 3412 KB Output is correct
32 Correct 66 ms 3340 KB Output is correct
33 Correct 57 ms 3288 KB Output is correct
34 Correct 52 ms 3332 KB Output is correct
35 Correct 47 ms 3412 KB Output is correct
36 Correct 47 ms 3412 KB Output is correct
37 Correct 77 ms 3384 KB Output is correct
38 Correct 76 ms 3412 KB Output is correct
39 Correct 97 ms 3428 KB Output is correct
40 Correct 99 ms 3404 KB Output is correct
41 Correct 86 ms 3296 KB Output is correct
42 Correct 74 ms 3408 KB Output is correct
43 Correct 72 ms 3408 KB Output is correct
44 Correct 97 ms 3352 KB Output is correct
45 Correct 81 ms 3408 KB Output is correct
46 Correct 76 ms 3408 KB Output is correct
47 Correct 91 ms 3320 KB Output is correct
48 Correct 74 ms 3308 KB Output is correct
49 Correct 67 ms 3244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 49 ms 3412 KB Output is correct
22 Correct 50 ms 3412 KB Output is correct
23 Correct 48 ms 3380 KB Output is correct
24 Correct 55 ms 3444 KB Output is correct
25 Correct 56 ms 3288 KB Output is correct
26 Correct 72 ms 3412 KB Output is correct
27 Correct 79 ms 3304 KB Output is correct
28 Correct 81 ms 3452 KB Output is correct
29 Correct 75 ms 3252 KB Output is correct
30 Correct 53 ms 3416 KB Output is correct
31 Correct 64 ms 3412 KB Output is correct
32 Correct 66 ms 3340 KB Output is correct
33 Correct 57 ms 3288 KB Output is correct
34 Correct 52 ms 3332 KB Output is correct
35 Correct 47 ms 3412 KB Output is correct
36 Correct 47 ms 3412 KB Output is correct
37 Correct 77 ms 3384 KB Output is correct
38 Correct 76 ms 3412 KB Output is correct
39 Correct 97 ms 3428 KB Output is correct
40 Correct 99 ms 3404 KB Output is correct
41 Correct 86 ms 3296 KB Output is correct
42 Correct 74 ms 3408 KB Output is correct
43 Correct 72 ms 3408 KB Output is correct
44 Correct 97 ms 3352 KB Output is correct
45 Correct 81 ms 3408 KB Output is correct
46 Correct 76 ms 3408 KB Output is correct
47 Correct 91 ms 3320 KB Output is correct
48 Correct 74 ms 3308 KB Output is correct
49 Correct 67 ms 3244 KB Output is correct
50 Execution timed out 1028 ms 13416 KB Time limit exceeded
51 Halted 0 ms 0 KB -