Submission #961466

# Submission time Handle Problem Language Result Execution time Memory
961466 2024-04-12T07:07:21 Z ByeWorld Cigle (COI21_cigle) C++14
48 / 100
1000 ms 13584 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
			}
		}
	}

	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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 616 KB Output is correct
12 Correct 1 ms 616 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 600 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 700 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3408 KB Output is correct
2 Correct 53 ms 3288 KB Output is correct
3 Correct 50 ms 3408 KB Output is correct
4 Correct 51 ms 3412 KB Output is correct
5 Correct 52 ms 3300 KB Output is correct
6 Correct 80 ms 3336 KB Output is correct
7 Correct 77 ms 3308 KB Output is correct
8 Correct 72 ms 3264 KB Output is correct
9 Correct 77 ms 3412 KB Output is correct
10 Correct 58 ms 3372 KB Output is correct
11 Correct 70 ms 3336 KB Output is correct
12 Correct 56 ms 3240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 616 KB Output is correct
12 Correct 1 ms 616 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 600 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 700 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 48 ms 3408 KB Output is correct
22 Correct 53 ms 3288 KB Output is correct
23 Correct 50 ms 3408 KB Output is correct
24 Correct 51 ms 3412 KB Output is correct
25 Correct 52 ms 3300 KB Output is correct
26 Correct 80 ms 3336 KB Output is correct
27 Correct 77 ms 3308 KB Output is correct
28 Correct 72 ms 3264 KB Output is correct
29 Correct 77 ms 3412 KB Output is correct
30 Correct 58 ms 3372 KB Output is correct
31 Correct 70 ms 3336 KB Output is correct
32 Correct 56 ms 3240 KB Output is correct
33 Correct 48 ms 3412 KB Output is correct
34 Correct 50 ms 3324 KB Output is correct
35 Correct 51 ms 3408 KB Output is correct
36 Correct 57 ms 3432 KB Output is correct
37 Correct 73 ms 3364 KB Output is correct
38 Correct 75 ms 3392 KB Output is correct
39 Correct 99 ms 3232 KB Output is correct
40 Correct 103 ms 3304 KB Output is correct
41 Correct 89 ms 3356 KB Output is correct
42 Correct 72 ms 3408 KB Output is correct
43 Correct 67 ms 3252 KB Output is correct
44 Correct 95 ms 3412 KB Output is correct
45 Correct 81 ms 3412 KB Output is correct
46 Correct 75 ms 3432 KB Output is correct
47 Correct 96 ms 3408 KB Output is correct
48 Correct 75 ms 3580 KB Output is correct
49 Correct 63 ms 3408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 616 KB Output is correct
12 Correct 1 ms 616 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 600 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 700 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 48 ms 3408 KB Output is correct
22 Correct 53 ms 3288 KB Output is correct
23 Correct 50 ms 3408 KB Output is correct
24 Correct 51 ms 3412 KB Output is correct
25 Correct 52 ms 3300 KB Output is correct
26 Correct 80 ms 3336 KB Output is correct
27 Correct 77 ms 3308 KB Output is correct
28 Correct 72 ms 3264 KB Output is correct
29 Correct 77 ms 3412 KB Output is correct
30 Correct 58 ms 3372 KB Output is correct
31 Correct 70 ms 3336 KB Output is correct
32 Correct 56 ms 3240 KB Output is correct
33 Correct 48 ms 3412 KB Output is correct
34 Correct 50 ms 3324 KB Output is correct
35 Correct 51 ms 3408 KB Output is correct
36 Correct 57 ms 3432 KB Output is correct
37 Correct 73 ms 3364 KB Output is correct
38 Correct 75 ms 3392 KB Output is correct
39 Correct 99 ms 3232 KB Output is correct
40 Correct 103 ms 3304 KB Output is correct
41 Correct 89 ms 3356 KB Output is correct
42 Correct 72 ms 3408 KB Output is correct
43 Correct 67 ms 3252 KB Output is correct
44 Correct 95 ms 3412 KB Output is correct
45 Correct 81 ms 3412 KB Output is correct
46 Correct 75 ms 3432 KB Output is correct
47 Correct 96 ms 3408 KB Output is correct
48 Correct 75 ms 3580 KB Output is correct
49 Correct 63 ms 3408 KB Output is correct
50 Execution timed out 1057 ms 13584 KB Time limit exceeded
51 Halted 0 ms 0 KB -