Submission #373746

# Submission time Handle Problem Language Result Execution time Memory
373746 2021-03-05T15:11:01 Z srvlt Bali Sculptures (APIO15_sculpture) C++14
100 / 100
804 ms 16248 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mem(x, y) memset(& x, y, sizeof(x))
#define all(x) begin(x), end(x)
#define SZ(x) (int)(x).size()
using namespace std;

const int n0=2003,n1=103;
int n,a,b,dp[n1][n1];
ll v[n0],ans;

int d[n0],g[n0][n0];
queue<int> q;
int bfs(int s) {
	mem(d,0x3f);
	d[s]=0;
	q.push(s);
	while(!q.empty()) {
		int v=q.front();q.pop();
		for(int i=0; i<=n; i++) {
			if(g[v][i] && d[i]>n0) {
				d[i]=d[v]+1;
				q.push(i);
			}
		}
	}
	return d[n];
}
bool ok(ll x) {
	if(n<n1) {
		mem(dp,0);
		dp[0][0]=1;
		for(int i=1; i<=b; i++) {
			for(int j=i; j<=n; j++) {
				for(int k=0; k<j; k++) {
					ll s=v[j]-v[k];
					if((s&x)!=s || !dp[i-1][k]) continue;
					dp[i][j]=1;
					break;
				}
			}
			if(i>=a && dp[i][n]) return 1;
		}
		return 0;
	}	else {
		assert(a==1);
		mem(g,0);
		for(int i=0; i<=n; i++) {
			for(int j=i+1; j<=n; j++) {
				ll s=v[j]-v[i];
				if((s&x)==s) {
					g[i][j]=1;
				}
			}
		}
		return bfs(0)<=b;
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> a >> b;
	for(int i=1; i<=n; i++) cin >> v[i],v[i]+=v[i-1];
	for(int i=45; i>=0; i--) {
		ll t=(1ll<<i)-1;
		if(!ok(ans|t)) ans|=1ll<<i;
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 480 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 42 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 42 ms 364 KB Output is correct
17 Correct 42 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 43 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 5 ms 364 KB Output is correct
29 Correct 5 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 3 ms 364 KB Output is correct
32 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 42 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 42 ms 364 KB Output is correct
26 Correct 82 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 41 ms 364 KB Output is correct
29 Correct 6 ms 236 KB Output is correct
30 Correct 42 ms 364 KB Output is correct
31 Correct 42 ms 384 KB Output is correct
32 Correct 42 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 1 ms 364 KB Output is correct
45 Correct 1 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 1 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 2 ms 364 KB Output is correct
50 Correct 3 ms 364 KB Output is correct
51 Correct 5 ms 364 KB Output is correct
52 Correct 74 ms 364 KB Output is correct
53 Correct 1 ms 364 KB Output is correct
54 Correct 4 ms 364 KB Output is correct
55 Correct 4 ms 364 KB Output is correct
56 Correct 2 ms 364 KB Output is correct
57 Correct 6 ms 364 KB Output is correct
58 Correct 13 ms 364 KB Output is correct
59 Correct 20 ms 364 KB Output is correct
60 Correct 20 ms 364 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 21 ms 364 KB Output is correct
63 Correct 20 ms 492 KB Output is correct
64 Correct 8 ms 364 KB Output is correct
65 Correct 3 ms 364 KB Output is correct
66 Correct 2 ms 364 KB Output is correct
67 Correct 5 ms 364 KB Output is correct
68 Correct 44 ms 364 KB Output is correct
69 Correct 85 ms 492 KB Output is correct
70 Correct 65 ms 364 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 21 ms 384 KB Output is correct
73 Correct 22 ms 364 KB Output is correct
74 Correct 19 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 41 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 41 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 44 ms 364 KB Output is correct
29 Correct 85 ms 392 KB Output is correct
30 Correct 38 ms 492 KB Output is correct
31 Correct 41 ms 492 KB Output is correct
32 Correct 40 ms 364 KB Output is correct
33 Correct 43 ms 364 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 2 ms 364 KB Output is correct
37 Correct 3 ms 364 KB Output is correct
38 Correct 5 ms 492 KB Output is correct
39 Correct 5 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 3 ms 364 KB Output is correct
42 Correct 5 ms 364 KB Output is correct
43 Correct 2 ms 364 KB Output is correct
44 Correct 6 ms 364 KB Output is correct
45 Correct 13 ms 492 KB Output is correct
46 Correct 20 ms 364 KB Output is correct
47 Correct 22 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 22 ms 364 KB Output is correct
50 Correct 20 ms 364 KB Output is correct
51 Correct 85 ms 364 KB Output is correct
52 Correct 134 ms 16108 KB Output is correct
53 Correct 144 ms 16108 KB Output is correct
54 Correct 269 ms 16108 KB Output is correct
55 Correct 244 ms 16108 KB Output is correct
56 Correct 451 ms 16236 KB Output is correct
57 Correct 443 ms 16236 KB Output is correct
58 Correct 527 ms 16152 KB Output is correct
59 Correct 683 ms 16236 KB Output is correct
60 Correct 495 ms 16236 KB Output is correct
61 Correct 7 ms 364 KB Output is correct
62 Correct 142 ms 16108 KB Output is correct
63 Correct 276 ms 16236 KB Output is correct
64 Correct 181 ms 16108 KB Output is correct
65 Correct 268 ms 16236 KB Output is correct
66 Correct 355 ms 16236 KB Output is correct
67 Correct 438 ms 16236 KB Output is correct
68 Correct 804 ms 16236 KB Output is correct
69 Correct 437 ms 16248 KB Output is correct