#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 5001
//~ #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];
}
# |
결과 |
실행 시간 |
메모리 |
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 |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
460 KB |
Output is correct |
8 |
Correct |
1 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 |
716 KB |
Output is correct |
15 |
Correct |
1 ms |
716 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4044 KB |
Output is correct |
2 |
Correct |
3 ms |
4556 KB |
Output is correct |
3 |
Correct |
3 ms |
4300 KB |
Output is correct |
4 |
Correct |
4 ms |
4300 KB |
Output is correct |
5 |
Correct |
4 ms |
4428 KB |
Output is correct |
6 |
Correct |
6 ms |
4428 KB |
Output is correct |
7 |
Correct |
5 ms |
4428 KB |
Output is correct |
8 |
Correct |
5 ms |
4428 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 |
4172 KB |
Output is correct |
12 |
Correct |
5 ms |
4172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
460 KB |
Output is correct |
8 |
Correct |
1 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 |
716 KB |
Output is correct |
15 |
Correct |
1 ms |
716 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 |
3 ms |
4044 KB |
Output is correct |
22 |
Correct |
3 ms |
4556 KB |
Output is correct |
23 |
Correct |
3 ms |
4300 KB |
Output is correct |
24 |
Correct |
4 ms |
4300 KB |
Output is correct |
25 |
Correct |
4 ms |
4428 KB |
Output is correct |
26 |
Correct |
6 ms |
4428 KB |
Output is correct |
27 |
Correct |
5 ms |
4428 KB |
Output is correct |
28 |
Correct |
5 ms |
4428 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 |
4172 KB |
Output is correct |
32 |
Correct |
5 ms |
4172 KB |
Output is correct |
33 |
Correct |
3 ms |
4044 KB |
Output is correct |
34 |
Correct |
5 ms |
4260 KB |
Output is correct |
35 |
Correct |
3 ms |
4328 KB |
Output is correct |
36 |
Correct |
3 ms |
4428 KB |
Output is correct |
37 |
Correct |
4 ms |
4428 KB |
Output is correct |
38 |
Correct |
4 ms |
4428 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 |
3404 KB |
Output is correct |
42 |
Correct |
4 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 |
3404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
460 KB |
Output is correct |
8 |
Correct |
1 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 |
716 KB |
Output is correct |
15 |
Correct |
1 ms |
716 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 |
3 ms |
4044 KB |
Output is correct |
22 |
Correct |
3 ms |
4556 KB |
Output is correct |
23 |
Correct |
3 ms |
4300 KB |
Output is correct |
24 |
Correct |
4 ms |
4300 KB |
Output is correct |
25 |
Correct |
4 ms |
4428 KB |
Output is correct |
26 |
Correct |
6 ms |
4428 KB |
Output is correct |
27 |
Correct |
5 ms |
4428 KB |
Output is correct |
28 |
Correct |
5 ms |
4428 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 |
4172 KB |
Output is correct |
32 |
Correct |
5 ms |
4172 KB |
Output is correct |
33 |
Correct |
3 ms |
4044 KB |
Output is correct |
34 |
Correct |
5 ms |
4260 KB |
Output is correct |
35 |
Correct |
3 ms |
4328 KB |
Output is correct |
36 |
Correct |
3 ms |
4428 KB |
Output is correct |
37 |
Correct |
4 ms |
4428 KB |
Output is correct |
38 |
Correct |
4 ms |
4428 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 |
3404 KB |
Output is correct |
42 |
Correct |
4 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 |
3404 KB |
Output is correct |
50 |
Incorrect |
314 ms |
195252 KB |
Output isn't correct |
51 |
Halted |
0 ms |
0 KB |
- |