Submission #1002881

# Submission time Handle Problem Language Result Execution time Memory
1002881 2024-06-19T20:59:59 Z Lalic Cigle (COI21_cigle) C++17
48 / 100
1000 ms 303824 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;

const int MAXN = 5e3+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);

//~ int dp[505][505][505];

//~ void solve(){
	//~ int n; cin >> n;
	
	//~ vector<int> arr(n+1); arr[0]=0;
	//~ for(int i=1;i<=n;i++) cin >> arr[i];
	
	//~ for(int i=3;i<=n;i++){
		//~ int sum=arr[i];
		
		//~ for(int c1=i-1;c1>=0;c1--){
			//~ int tot=arr[c1], best=0;
			//~ bool ok=0;
			
			//~ for(int c2=c1-1;c2>=0;c2--){
				//~ if(ok && tot>sum) dp[i][c1][c2]=dp[i-1][c1][c2]+1;
				//~ else{
					//~ if(tot==sum) ok=1;
					//~ dp[i][c1][c2]=dp[i-1][c1][c2];
				//~ }
				
				//~ tot+=arr[c2];
				//~ best=max(best, dp[i-1][c1][c2]);
			//~ }
			
			//~ sum+=arr[c1];
			//~ dp[i][i][c1]=best;
		//~ }
	//~ }
	
	//~ int ans=0;
	//~ for(int i=0;i<n;i++) ans=max(ans, dp[n][n][i]);
	
	//~ cout << ans << "\n";
//~ }

int tree[MAXN][4*MAXN], lazy[MAXN][4*MAXN];

void lazyP(int id, int node, int l, int r){
	if(!lazy[id][node]) return;
	
	tree[id][node]+=lazy[id][node];
	if(l!=r){
		lazy[id][node*2]+=lazy[id][node];
		lazy[id][node*2+1]+=lazy[id][node];
	}
	lazy[id][node]=0;
}

void upd(int id, int node, int l, int r, int p, int q, int val){
	lazyP(id, node, l, r);
	
	if(r<p || l>q) return;
	if(l>=p && r<=q){
		lazy[id][node]+=val;
		lazyP(id, node, l, r);
		return;
	}
	
	int mid=(l+r)>>1;
	upd(id, node*2, l, mid, p, q, val);
	upd(id, node*2+1, mid+1, r, p, q, val);
	
	tree[id][node]=max(tree[id][node*2], tree[id][node*2+1]);
}

int query(int id, int node, int l, int r, int p, int q){
	lazyP(id, node, l, r);
	
	if(r<p || l>q) return 0;
	if(l>=p && r<=q) return tree[id][node];
	
	int mid=(l+r)>>1;
	return max(query(id, node*2, l, mid, p, q), query(id, node*2+1, mid+1, r, p, q));
}

void solve(){
	int n; cin >> n;
	
	vector<int> arr(n+1);
	for(int i=1;i<=n;i++) cin >> arr[i];
	
	for(int i=3;i<=n;i++){
		int sum=arr[i], c2=i-2, tot=arr[i-1];
		
		for(int c1=i-1;c1>=0;c1--){
			upd(i, 1, 0, n, c1, c1, query(c1, 1, 0, n, 0, n));
			
			while(c2>0 && tot<sum){
				tot+=arr[c2];
				c2--;
			}
			
			if(tot==sum && c2>0){
				upd(c1, 1, 0, n, 0, c2-1, 1);
				//~ cout << i << " " << c1 << " " << c2 << "\n";
				//~ for(int j=0;j<=c2-1;j++) cout << query(c1, 1, 0, n, j, j) << "\n";
			}
			
			sum+=arr[c1];
			tot-=arr[c1];
		}
	}
	
	cout << query(n, 1, 0, n, 0, n) << "\n";
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	int tt=1;
	//~ cin >> tt;
	while(tt--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1128 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1112 KB Output is correct
20 Correct 1 ms 1112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 10588 KB Output is correct
2 Correct 21 ms 10588 KB Output is correct
3 Correct 22 ms 10436 KB Output is correct
4 Correct 22 ms 10588 KB Output is correct
5 Correct 20 ms 10588 KB Output is correct
6 Correct 23 ms 10588 KB Output is correct
7 Correct 21 ms 10588 KB Output is correct
8 Correct 24 ms 10580 KB Output is correct
9 Correct 25 ms 10576 KB Output is correct
10 Correct 23 ms 10580 KB Output is correct
11 Correct 23 ms 10552 KB Output is correct
12 Correct 22 ms 10548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1128 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1112 KB Output is correct
20 Correct 1 ms 1112 KB Output is correct
21 Correct 18 ms 10588 KB Output is correct
22 Correct 21 ms 10588 KB Output is correct
23 Correct 22 ms 10436 KB Output is correct
24 Correct 22 ms 10588 KB Output is correct
25 Correct 20 ms 10588 KB Output is correct
26 Correct 23 ms 10588 KB Output is correct
27 Correct 21 ms 10588 KB Output is correct
28 Correct 24 ms 10580 KB Output is correct
29 Correct 25 ms 10576 KB Output is correct
30 Correct 23 ms 10580 KB Output is correct
31 Correct 23 ms 10552 KB Output is correct
32 Correct 22 ms 10548 KB Output is correct
33 Correct 22 ms 10576 KB Output is correct
34 Correct 24 ms 10548 KB Output is correct
35 Correct 22 ms 10576 KB Output is correct
36 Correct 28 ms 10580 KB Output is correct
37 Correct 27 ms 10576 KB Output is correct
38 Correct 25 ms 10588 KB Output is correct
39 Correct 20 ms 10584 KB Output is correct
40 Correct 18 ms 9052 KB Output is correct
41 Correct 17 ms 10072 KB Output is correct
42 Correct 17 ms 10332 KB Output is correct
43 Correct 17 ms 10072 KB Output is correct
44 Correct 18 ms 9308 KB Output is correct
45 Correct 16 ms 10072 KB Output is correct
46 Correct 18 ms 9992 KB Output is correct
47 Correct 16 ms 9820 KB Output is correct
48 Correct 17 ms 9820 KB Output is correct
49 Correct 16 ms 10196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 464 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1116 KB Output is correct
17 Correct 1 ms 1128 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1112 KB Output is correct
20 Correct 1 ms 1112 KB Output is correct
21 Correct 18 ms 10588 KB Output is correct
22 Correct 21 ms 10588 KB Output is correct
23 Correct 22 ms 10436 KB Output is correct
24 Correct 22 ms 10588 KB Output is correct
25 Correct 20 ms 10588 KB Output is correct
26 Correct 23 ms 10588 KB Output is correct
27 Correct 21 ms 10588 KB Output is correct
28 Correct 24 ms 10580 KB Output is correct
29 Correct 25 ms 10576 KB Output is correct
30 Correct 23 ms 10580 KB Output is correct
31 Correct 23 ms 10552 KB Output is correct
32 Correct 22 ms 10548 KB Output is correct
33 Correct 22 ms 10576 KB Output is correct
34 Correct 24 ms 10548 KB Output is correct
35 Correct 22 ms 10576 KB Output is correct
36 Correct 28 ms 10580 KB Output is correct
37 Correct 27 ms 10576 KB Output is correct
38 Correct 25 ms 10588 KB Output is correct
39 Correct 20 ms 10584 KB Output is correct
40 Correct 18 ms 9052 KB Output is correct
41 Correct 17 ms 10072 KB Output is correct
42 Correct 17 ms 10332 KB Output is correct
43 Correct 17 ms 10072 KB Output is correct
44 Correct 18 ms 9308 KB Output is correct
45 Correct 16 ms 10072 KB Output is correct
46 Correct 18 ms 9992 KB Output is correct
47 Correct 16 ms 9820 KB Output is correct
48 Correct 17 ms 9820 KB Output is correct
49 Correct 16 ms 10196 KB Output is correct
50 Execution timed out 1060 ms 303824 KB Time limit exceeded
51 Halted 0 ms 0 KB -