Submission #423043

# Submission time Handle Problem Language Result Execution time Memory
423043 2021-06-10T16:24:20 Z errorgorn Cigle (COI21_cigle) C++17
100 / 100
340 ms 67396 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n;
int arr[5005];

int memo[5005][5005];

int temp[5005];
int ptemp[5005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n;
	rep(x,1,n+1) cin>>arr[x];
	
	temp[0]=ptemp[0]=-1e9;
	
	rep(x,2,n){
		rep(y,1,x) temp[y]=memo[y][x-1];
		rep(y,1,x) ptemp[y]=max(ptemp[y-1],temp[y]);
		
		int b=x-1;
		int bs=0;
		int fs=0;
		int curr=0;
		int add=0;
		rep(y,x,n+1){
			if (y!=x) fs+=arr[y-1];
			while (bs<fs){
				if (b){
					curr=max(curr,temp[b]);
					bs+=arr[b--];
				}
				else break;
			}
			
			//cout<<x<<" "<<y<<" "<<b<<" "<<bs<<" "<<fs<<endl;
			if (y!=x && bs==fs){
				curr--;
				add++;
			}
			
			memo[x][y]=ptemp[b]+add;
			memo[x][y]=max(memo[x][y],curr+add);
			
			//cout<<x<<" "<<y<<" "<<memo[x][y]<<endl;
		}
	}
	
	int ans=0;
	rep(x,1,n+1) ans=max(ans,memo[x][n]);
	cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 580 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2764 KB Output is correct
2 Correct 3 ms 2764 KB Output is correct
3 Correct 3 ms 2764 KB Output is correct
4 Correct 3 ms 2756 KB Output is correct
5 Correct 3 ms 2764 KB Output is correct
6 Correct 4 ms 2764 KB Output is correct
7 Correct 4 ms 2776 KB Output is correct
8 Correct 4 ms 2760 KB Output is correct
9 Correct 4 ms 2764 KB Output is correct
10 Correct 3 ms 2764 KB Output is correct
11 Correct 4 ms 2764 KB Output is correct
12 Correct 3 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 580 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 3 ms 2764 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Correct 3 ms 2764 KB Output is correct
24 Correct 3 ms 2756 KB Output is correct
25 Correct 3 ms 2764 KB Output is correct
26 Correct 4 ms 2764 KB Output is correct
27 Correct 4 ms 2776 KB Output is correct
28 Correct 4 ms 2760 KB Output is correct
29 Correct 4 ms 2764 KB Output is correct
30 Correct 3 ms 2764 KB Output is correct
31 Correct 4 ms 2764 KB Output is correct
32 Correct 3 ms 2764 KB Output is correct
33 Correct 3 ms 2764 KB Output is correct
34 Correct 3 ms 2764 KB Output is correct
35 Correct 3 ms 2756 KB Output is correct
36 Correct 4 ms 2764 KB Output is correct
37 Correct 4 ms 2764 KB Output is correct
38 Correct 4 ms 2764 KB Output is correct
39 Correct 4 ms 2764 KB Output is correct
40 Correct 4 ms 2764 KB Output is correct
41 Correct 3 ms 2728 KB Output is correct
42 Correct 3 ms 2764 KB Output is correct
43 Correct 3 ms 2764 KB Output is correct
44 Correct 4 ms 2764 KB Output is correct
45 Correct 3 ms 2764 KB Output is correct
46 Correct 4 ms 2764 KB Output is correct
47 Correct 4 ms 2764 KB Output is correct
48 Correct 4 ms 2764 KB Output is correct
49 Correct 3 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 580 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 1 ms 588 KB Output is correct
18 Correct 1 ms 588 KB Output is correct
19 Correct 1 ms 588 KB Output is correct
20 Correct 1 ms 588 KB Output is correct
21 Correct 3 ms 2764 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Correct 3 ms 2764 KB Output is correct
24 Correct 3 ms 2756 KB Output is correct
25 Correct 3 ms 2764 KB Output is correct
26 Correct 4 ms 2764 KB Output is correct
27 Correct 4 ms 2776 KB Output is correct
28 Correct 4 ms 2760 KB Output is correct
29 Correct 4 ms 2764 KB Output is correct
30 Correct 3 ms 2764 KB Output is correct
31 Correct 4 ms 2764 KB Output is correct
32 Correct 3 ms 2764 KB Output is correct
33 Correct 3 ms 2764 KB Output is correct
34 Correct 3 ms 2764 KB Output is correct
35 Correct 3 ms 2756 KB Output is correct
36 Correct 4 ms 2764 KB Output is correct
37 Correct 4 ms 2764 KB Output is correct
38 Correct 4 ms 2764 KB Output is correct
39 Correct 4 ms 2764 KB Output is correct
40 Correct 4 ms 2764 KB Output is correct
41 Correct 3 ms 2728 KB Output is correct
42 Correct 3 ms 2764 KB Output is correct
43 Correct 3 ms 2764 KB Output is correct
44 Correct 4 ms 2764 KB Output is correct
45 Correct 3 ms 2764 KB Output is correct
46 Correct 4 ms 2764 KB Output is correct
47 Correct 4 ms 2764 KB Output is correct
48 Correct 4 ms 2764 KB Output is correct
49 Correct 3 ms 2764 KB Output is correct
50 Correct 256 ms 67232 KB Output is correct
51 Correct 261 ms 67376 KB Output is correct
52 Correct 267 ms 67312 KB Output is correct
53 Correct 287 ms 67392 KB Output is correct
54 Correct 273 ms 67300 KB Output is correct
55 Correct 262 ms 67340 KB Output is correct
56 Correct 335 ms 67224 KB Output is correct
57 Correct 330 ms 67272 KB Output is correct
58 Correct 332 ms 67316 KB Output is correct
59 Correct 326 ms 67396 KB Output is correct
60 Correct 339 ms 67296 KB Output is correct
61 Correct 294 ms 67232 KB Output is correct
62 Correct 293 ms 67308 KB Output is correct
63 Correct 324 ms 67268 KB Output is correct
64 Correct 285 ms 67296 KB Output is correct
65 Correct 296 ms 67300 KB Output is correct
66 Correct 290 ms 67268 KB Output is correct
67 Correct 278 ms 67308 KB Output is correct
68 Correct 268 ms 67336 KB Output is correct
69 Correct 273 ms 67244 KB Output is correct
70 Correct 312 ms 67372 KB Output is correct
71 Correct 340 ms 67292 KB Output is correct
72 Correct 301 ms 67288 KB Output is correct