Submission #530406

# Submission time Handle Problem Language Result Execution time Memory
530406 2022-02-25T09:46:54 Z jiahng Cigle (COI21_cigle) C++14
100 / 100
385 ms 200932 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define maxn 5010
//~ #define getchar_unlocked _getchar_nolock

int N,D[maxn],ss[maxn];

inline int readInt() {
    int x = 0;
    char ch = getchar_unlocked();
    while (ch < '0' || ch > '9') ch = getchar_unlocked();
    while (ch >= '0' && ch <= '9'){
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar_unlocked();
	}
    return x;
}

vpi A[maxn];
int dp[maxn][maxn];

int updates[maxn];
int32_t main() {
    fast;
    N = readInt();
    FOR(i,1,N){
		D[i] = readInt();
		ss[i] = ss[i-1] + D[i];
	}
	FOR(l,2,N) FOR(r,l+1,N-1) if ((ss[l-1] + ss[r]) % 2 == 0){
		int ssb = (ss[l-1] + ss[r]) / 2;
		int b = lower_bound(ss+l,ss+r,ssb) - ss;
		if (ss[b] == ssb ){
			//~ cout << l-1 << ' ' << b << ' ' << r << '\n';
			A[b].pb(pi(l-1,r));
		}
	}
	FOR(i,0,N) reverse(all(A[i]));
	
	
	DEC(i,N,1){
		FOR(k,0,A[i].size()-1){
			int newdp = dp[max(i,A[i][k].s+1)][i] + k + 1;
			if (A[i][k].f - 1 >= 0) updates[A[i][k].f-1] = max(updates[A[i][k].f-1], newdp);
		}
		int mx = 0;
		DEC(j,i-1,0){
			mx = max(mx, updates[j]);
			updates[j] = -1;
			dp[i][j] = max(dp[i+1][j], mx);
		}
	}

	cout << dp[1][0];
	
}	

# 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 0 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 0 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is 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 0 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 0 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 716 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4064 KB Output is correct
2 Correct 3 ms 4556 KB Output is correct
3 Correct 3 ms 4300 KB Output is correct
4 Correct 3 ms 4300 KB Output is correct
5 Correct 5 ms 4428 KB Output is correct
6 Correct 6 ms 4428 KB Output is correct
7 Correct 7 ms 4428 KB Output is correct
8 Correct 5 ms 4360 KB Output is correct
9 Correct 5 ms 4428 KB Output is correct
10 Correct 4 ms 4300 KB Output is correct
11 Correct 6 ms 4300 KB Output is correct
12 Correct 4 ms 4300 KB Output is 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 0 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 0 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 716 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 1 ms 716 KB Output is correct
21 Correct 4 ms 4064 KB Output is correct
22 Correct 3 ms 4556 KB Output is correct
23 Correct 3 ms 4300 KB Output is correct
24 Correct 3 ms 4300 KB Output is correct
25 Correct 5 ms 4428 KB Output is correct
26 Correct 6 ms 4428 KB Output is correct
27 Correct 7 ms 4428 KB Output is correct
28 Correct 5 ms 4360 KB Output is correct
29 Correct 5 ms 4428 KB Output is correct
30 Correct 4 ms 4300 KB Output is correct
31 Correct 6 ms 4300 KB Output is correct
32 Correct 4 ms 4300 KB Output is correct
33 Correct 3 ms 4044 KB Output is correct
34 Correct 3 ms 4300 KB Output is correct
35 Correct 3 ms 4228 KB Output is correct
36 Correct 3 ms 4428 KB Output is correct
37 Correct 5 ms 4428 KB Output is correct
38 Correct 6 ms 4336 KB Output is correct
39 Correct 4 ms 3660 KB Output is correct
40 Correct 4 ms 3404 KB Output is correct
41 Correct 3 ms 3408 KB Output is correct
42 Correct 3 ms 3404 KB Output is correct
43 Correct 3 ms 3404 KB Output is correct
44 Correct 3 ms 3404 KB Output is correct
45 Correct 3 ms 3404 KB Output is correct
46 Correct 3 ms 3404 KB Output is correct
47 Correct 3 ms 3404 KB Output is correct
48 Correct 3 ms 3404 KB Output is correct
49 Correct 3 ms 3420 KB Output is 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 0 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 0 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 844 KB Output is correct
15 Correct 1 ms 844 KB Output is correct
16 Correct 1 ms 716 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 716 KB Output is correct
19 Correct 1 ms 716 KB Output is correct
20 Correct 1 ms 716 KB Output is correct
21 Correct 4 ms 4064 KB Output is correct
22 Correct 3 ms 4556 KB Output is correct
23 Correct 3 ms 4300 KB Output is correct
24 Correct 3 ms 4300 KB Output is correct
25 Correct 5 ms 4428 KB Output is correct
26 Correct 6 ms 4428 KB Output is correct
27 Correct 7 ms 4428 KB Output is correct
28 Correct 5 ms 4360 KB Output is correct
29 Correct 5 ms 4428 KB Output is correct
30 Correct 4 ms 4300 KB Output is correct
31 Correct 6 ms 4300 KB Output is correct
32 Correct 4 ms 4300 KB Output is correct
33 Correct 3 ms 4044 KB Output is correct
34 Correct 3 ms 4300 KB Output is correct
35 Correct 3 ms 4228 KB Output is correct
36 Correct 3 ms 4428 KB Output is correct
37 Correct 5 ms 4428 KB Output is correct
38 Correct 6 ms 4336 KB Output is correct
39 Correct 4 ms 3660 KB Output is correct
40 Correct 4 ms 3404 KB Output is correct
41 Correct 3 ms 3408 KB Output is correct
42 Correct 3 ms 3404 KB Output is correct
43 Correct 3 ms 3404 KB Output is correct
44 Correct 3 ms 3404 KB Output is correct
45 Correct 3 ms 3404 KB Output is correct
46 Correct 3 ms 3404 KB Output is correct
47 Correct 3 ms 3404 KB Output is correct
48 Correct 3 ms 3404 KB Output is correct
49 Correct 3 ms 3420 KB Output is correct
50 Correct 298 ms 195284 KB Output is correct
51 Correct 258 ms 192672 KB Output is correct
52 Correct 299 ms 195844 KB Output is correct
53 Correct 293 ms 195032 KB Output is correct
54 Correct 266 ms 196384 KB Output is correct
55 Correct 271 ms 195412 KB Output is correct
56 Correct 385 ms 200908 KB Output is correct
57 Correct 385 ms 200932 KB Output is correct
58 Correct 329 ms 142660 KB Output is correct
59 Correct 334 ms 123248 KB Output is correct
60 Correct 267 ms 117784 KB Output is correct
61 Correct 246 ms 117848 KB Output is correct
62 Correct 212 ms 117944 KB Output is correct
63 Correct 199 ms 118804 KB Output is correct
64 Correct 249 ms 118380 KB Output is correct
65 Correct 192 ms 118504 KB Output is correct
66 Correct 237 ms 118192 KB Output is correct
67 Correct 192 ms 118616 KB Output is correct
68 Correct 161 ms 118556 KB Output is correct
69 Correct 177 ms 118844 KB Output is correct
70 Correct 315 ms 117856 KB Output is correct
71 Correct 295 ms 117896 KB Output is correct
72 Correct 271 ms 118672 KB Output is correct