#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
*/
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
#define maxn 5005
ll n;
ll a[maxn];
ll ps[maxn];
ll dpmax[maxn];
ll dp[maxn][maxn];
int main(){
daj_mi_malo_vremena
cin >> n;
for(ll i = 1;i<=n;i++) cin >> a[i];
for(ll l = 1;l<=n;l++){
ll j = l, cur = 0;
for(ll i = 1;i<l;i++) dpmax[i] = max(dpmax[i-1],dp[i][l-1]);
ll delta = 0;
ll len = 0;
for(ll r = l+1;r<=n;r++){
dp[l][r] = dp[l][r-1];
len+=a[r-1];
while(j>2&&cur<len)j--,cur+=a[j];
if(cur==len){
delta++;
dp[l][r] = max(dp[l][r],dpmax[j-1]+delta);
}
}
}
ll ans = 0;
for(ll i = 1;i<=n;i++) ans = max(ans,dp[i][n]);
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3284 KB |
Output is correct |
2 |
Correct |
3 ms |
3284 KB |
Output is correct |
3 |
Correct |
3 ms |
3284 KB |
Output is correct |
4 |
Correct |
3 ms |
3284 KB |
Output is correct |
5 |
Correct |
3 ms |
3284 KB |
Output is correct |
6 |
Correct |
3 ms |
3284 KB |
Output is correct |
7 |
Correct |
4 ms |
3284 KB |
Output is correct |
8 |
Correct |
3 ms |
3284 KB |
Output is correct |
9 |
Correct |
3 ms |
3284 KB |
Output is correct |
10 |
Correct |
3 ms |
3284 KB |
Output is correct |
11 |
Correct |
3 ms |
3284 KB |
Output is correct |
12 |
Correct |
3 ms |
3284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
3 ms |
3284 KB |
Output is correct |
22 |
Correct |
3 ms |
3284 KB |
Output is correct |
23 |
Correct |
3 ms |
3284 KB |
Output is correct |
24 |
Correct |
3 ms |
3284 KB |
Output is correct |
25 |
Correct |
3 ms |
3284 KB |
Output is correct |
26 |
Correct |
3 ms |
3284 KB |
Output is correct |
27 |
Correct |
4 ms |
3284 KB |
Output is correct |
28 |
Correct |
3 ms |
3284 KB |
Output is correct |
29 |
Correct |
3 ms |
3284 KB |
Output is correct |
30 |
Correct |
3 ms |
3284 KB |
Output is correct |
31 |
Correct |
3 ms |
3284 KB |
Output is correct |
32 |
Correct |
3 ms |
3284 KB |
Output is correct |
33 |
Correct |
3 ms |
3224 KB |
Output is correct |
34 |
Correct |
3 ms |
3308 KB |
Output is correct |
35 |
Correct |
4 ms |
3284 KB |
Output is correct |
36 |
Correct |
3 ms |
3284 KB |
Output is correct |
37 |
Correct |
3 ms |
3284 KB |
Output is correct |
38 |
Correct |
4 ms |
3284 KB |
Output is correct |
39 |
Correct |
3 ms |
3284 KB |
Output is correct |
40 |
Correct |
3 ms |
3284 KB |
Output is correct |
41 |
Correct |
4 ms |
3284 KB |
Output is correct |
42 |
Correct |
3 ms |
3284 KB |
Output is correct |
43 |
Correct |
3 ms |
3284 KB |
Output is correct |
44 |
Correct |
3 ms |
3356 KB |
Output is correct |
45 |
Correct |
3 ms |
3284 KB |
Output is correct |
46 |
Correct |
4 ms |
3284 KB |
Output is correct |
47 |
Correct |
3 ms |
3284 KB |
Output is correct |
48 |
Correct |
3 ms |
3284 KB |
Output is correct |
49 |
Correct |
3 ms |
3284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
3 ms |
3284 KB |
Output is correct |
22 |
Correct |
3 ms |
3284 KB |
Output is correct |
23 |
Correct |
3 ms |
3284 KB |
Output is correct |
24 |
Correct |
3 ms |
3284 KB |
Output is correct |
25 |
Correct |
3 ms |
3284 KB |
Output is correct |
26 |
Correct |
3 ms |
3284 KB |
Output is correct |
27 |
Correct |
4 ms |
3284 KB |
Output is correct |
28 |
Correct |
3 ms |
3284 KB |
Output is correct |
29 |
Correct |
3 ms |
3284 KB |
Output is correct |
30 |
Correct |
3 ms |
3284 KB |
Output is correct |
31 |
Correct |
3 ms |
3284 KB |
Output is correct |
32 |
Correct |
3 ms |
3284 KB |
Output is correct |
33 |
Correct |
3 ms |
3224 KB |
Output is correct |
34 |
Correct |
3 ms |
3308 KB |
Output is correct |
35 |
Correct |
4 ms |
3284 KB |
Output is correct |
36 |
Correct |
3 ms |
3284 KB |
Output is correct |
37 |
Correct |
3 ms |
3284 KB |
Output is correct |
38 |
Correct |
4 ms |
3284 KB |
Output is correct |
39 |
Correct |
3 ms |
3284 KB |
Output is correct |
40 |
Correct |
3 ms |
3284 KB |
Output is correct |
41 |
Correct |
4 ms |
3284 KB |
Output is correct |
42 |
Correct |
3 ms |
3284 KB |
Output is correct |
43 |
Correct |
3 ms |
3284 KB |
Output is correct |
44 |
Correct |
3 ms |
3356 KB |
Output is correct |
45 |
Correct |
3 ms |
3284 KB |
Output is correct |
46 |
Correct |
4 ms |
3284 KB |
Output is correct |
47 |
Correct |
3 ms |
3284 KB |
Output is correct |
48 |
Correct |
3 ms |
3284 KB |
Output is correct |
49 |
Correct |
3 ms |
3284 KB |
Output is correct |
50 |
Correct |
201 ms |
117332 KB |
Output is correct |
51 |
Correct |
200 ms |
117308 KB |
Output is correct |
52 |
Correct |
200 ms |
117404 KB |
Output is correct |
53 |
Correct |
208 ms |
117368 KB |
Output is correct |
54 |
Correct |
206 ms |
117344 KB |
Output is correct |
55 |
Correct |
204 ms |
117400 KB |
Output is correct |
56 |
Correct |
230 ms |
117296 KB |
Output is correct |
57 |
Correct |
220 ms |
117352 KB |
Output is correct |
58 |
Correct |
236 ms |
117500 KB |
Output is correct |
59 |
Correct |
251 ms |
117324 KB |
Output is correct |
60 |
Correct |
225 ms |
117392 KB |
Output is correct |
61 |
Correct |
219 ms |
117292 KB |
Output is correct |
62 |
Correct |
225 ms |
117324 KB |
Output is correct |
63 |
Correct |
197 ms |
117308 KB |
Output is correct |
64 |
Correct |
211 ms |
117336 KB |
Output is correct |
65 |
Correct |
202 ms |
117324 KB |
Output is correct |
66 |
Correct |
215 ms |
117364 KB |
Output is correct |
67 |
Correct |
199 ms |
117468 KB |
Output is correct |
68 |
Correct |
197 ms |
117464 KB |
Output is correct |
69 |
Correct |
198 ms |
117372 KB |
Output is correct |
70 |
Correct |
230 ms |
117420 KB |
Output is correct |
71 |
Correct |
231 ms |
117340 KB |
Output is correct |
72 |
Correct |
238 ms |
117404 KB |
Output is correct |