Submission #1002891

# Submission time Handle Problem Language Result Execution time Memory
1002891 2024-06-19T21:04:50 Z Lalic Cigle (COI21_cigle) C++17
48 / 100
1000 ms 404748 KB
#include <bits/stdc++.h>
#pragma GCC optimize "O3,unroll-loops"
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 = 5005;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);

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);
			
			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 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 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 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 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 600 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1112 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 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 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 10464 KB Output is correct
2 Correct 20 ms 10580 KB Output is correct
3 Correct 19 ms 10588 KB Output is correct
4 Correct 20 ms 10584 KB Output is correct
5 Correct 19 ms 10588 KB Output is correct
6 Correct 20 ms 10588 KB Output is correct
7 Correct 25 ms 10580 KB Output is correct
8 Correct 20 ms 10588 KB Output is correct
9 Correct 20 ms 10516 KB Output is correct
10 Correct 19 ms 10436 KB Output is correct
11 Correct 18 ms 10588 KB Output is correct
12 Correct 18 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 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 600 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1112 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 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 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 18 ms 10464 KB Output is correct
22 Correct 20 ms 10580 KB Output is correct
23 Correct 19 ms 10588 KB Output is correct
24 Correct 20 ms 10584 KB Output is correct
25 Correct 19 ms 10588 KB Output is correct
26 Correct 20 ms 10588 KB Output is correct
27 Correct 25 ms 10580 KB Output is correct
28 Correct 20 ms 10588 KB Output is correct
29 Correct 20 ms 10516 KB Output is correct
30 Correct 19 ms 10436 KB Output is correct
31 Correct 18 ms 10588 KB Output is correct
32 Correct 18 ms 10588 KB Output is correct
33 Correct 18 ms 10588 KB Output is correct
34 Correct 19 ms 10588 KB Output is correct
35 Correct 18 ms 10596 KB Output is correct
36 Correct 20 ms 10584 KB Output is correct
37 Correct 18 ms 10692 KB Output is correct
38 Correct 16 ms 10588 KB Output is correct
39 Correct 16 ms 10520 KB Output is correct
40 Correct 13 ms 9052 KB Output is correct
41 Correct 13 ms 9864 KB Output is correct
42 Correct 14 ms 10332 KB Output is correct
43 Correct 13 ms 10076 KB Output is correct
44 Correct 14 ms 9280 KB Output is correct
45 Correct 14 ms 10076 KB Output is correct
46 Correct 17 ms 9868 KB Output is correct
47 Correct 13 ms 9564 KB Output is correct
48 Correct 13 ms 9820 KB Output is correct
49 Correct 13 ms 9976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 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 600 KB Output is correct
10 Correct 1 ms 1372 KB Output is correct
11 Correct 1 ms 1112 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 1 ms 1116 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 1116 KB Output is correct
18 Correct 1 ms 1116 KB Output is correct
19 Correct 1 ms 1116 KB Output is correct
20 Correct 1 ms 1116 KB Output is correct
21 Correct 18 ms 10464 KB Output is correct
22 Correct 20 ms 10580 KB Output is correct
23 Correct 19 ms 10588 KB Output is correct
24 Correct 20 ms 10584 KB Output is correct
25 Correct 19 ms 10588 KB Output is correct
26 Correct 20 ms 10588 KB Output is correct
27 Correct 25 ms 10580 KB Output is correct
28 Correct 20 ms 10588 KB Output is correct
29 Correct 20 ms 10516 KB Output is correct
30 Correct 19 ms 10436 KB Output is correct
31 Correct 18 ms 10588 KB Output is correct
32 Correct 18 ms 10588 KB Output is correct
33 Correct 18 ms 10588 KB Output is correct
34 Correct 19 ms 10588 KB Output is correct
35 Correct 18 ms 10596 KB Output is correct
36 Correct 20 ms 10584 KB Output is correct
37 Correct 18 ms 10692 KB Output is correct
38 Correct 16 ms 10588 KB Output is correct
39 Correct 16 ms 10520 KB Output is correct
40 Correct 13 ms 9052 KB Output is correct
41 Correct 13 ms 9864 KB Output is correct
42 Correct 14 ms 10332 KB Output is correct
43 Correct 13 ms 10076 KB Output is correct
44 Correct 14 ms 9280 KB Output is correct
45 Correct 14 ms 10076 KB Output is correct
46 Correct 17 ms 9868 KB Output is correct
47 Correct 13 ms 9564 KB Output is correct
48 Correct 13 ms 9820 KB Output is correct
49 Correct 13 ms 9976 KB Output is correct
50 Execution timed out 1113 ms 404748 KB Time limit exceeded
51 Halted 0 ms 0 KB -