Submission #373747

# Submission time Handle Problem Language Result Execution time Memory
373747 2021-03-05T15:17:31 Z srvlt Bali Sculptures (APIO15_sculpture) C++14
100 / 100
705 ms 1004 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];
bitset<n0> g[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);
		for(int i=0; i<=n; i++) g[i].reset();
		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 404 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 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 42 ms 364 KB Output is correct
19 Correct 1 ms 384 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 33 ms 364 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 78 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 504 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 40 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 512 KB Output is correct
24 Correct 41 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 31 ms 364 KB Output is correct
28 Correct 40 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 33 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 42 ms 364 KB Output is correct
34 Correct 85 ms 364 KB Output is correct
35 Correct 1 ms 492 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 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 43 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 42 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 42 ms 364 KB Output is correct
25 Correct 83 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 3 ms 364 KB Output is correct
28 Correct 3 ms 364 KB Output is correct
29 Correct 4 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 85 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 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 45 ms 364 KB Output is correct
5 Correct 1 ms 396 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 45 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
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 43 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 1 ms 364 KB Output is correct
50 Correct 3 ms 364 KB Output is correct
51 Correct 3 ms 364 KB Output is correct
52 Correct 5 ms 364 KB Output is correct
53 Correct 1 ms 492 KB Output is correct
54 Correct 3 ms 364 KB Output is correct
55 Correct 3 ms 364 KB Output is correct
56 Correct 2 ms 364 KB Output is correct
57 Correct 4 ms 364 KB Output is correct
58 Correct 9 ms 364 KB Output is correct
59 Correct 85 ms 364 KB Output is correct
60 Correct 15 ms 492 KB Output is correct
61 Correct 1 ms 364 KB Output is correct
62 Correct 14 ms 364 KB Output is correct
63 Correct 14 ms 364 KB Output is correct
64 Correct 7 ms 364 KB Output is correct
65 Correct 2 ms 364 KB Output is correct
66 Correct 2 ms 364 KB Output is correct
67 Correct 6 ms 364 KB Output is correct
68 Correct 10 ms 364 KB Output is correct
69 Correct 19 ms 364 KB Output is correct
70 Correct 18 ms 448 KB Output is correct
71 Correct 1 ms 364 KB Output is correct
72 Correct 15 ms 364 KB Output is correct
73 Correct 16 ms 364 KB Output is correct
74 Correct 14 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 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 384 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 384 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 3 ms 364 KB Output is correct
38 Correct 3 ms 364 KB Output is correct
39 Correct 4 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 4 ms 364 KB Output is correct
42 Correct 3 ms 364 KB Output is correct
43 Correct 2 ms 364 KB Output is correct
44 Correct 4 ms 364 KB Output is correct
45 Correct 9 ms 364 KB Output is correct
46 Correct 14 ms 364 KB Output is correct
47 Correct 14 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 15 ms 364 KB Output is correct
50 Correct 15 ms 364 KB Output is correct
51 Correct 5 ms 364 KB Output is correct
52 Correct 43 ms 492 KB Output is correct
53 Correct 47 ms 620 KB Output is correct
54 Correct 179 ms 620 KB Output is correct
55 Correct 135 ms 620 KB Output is correct
56 Correct 336 ms 876 KB Output is correct
57 Correct 326 ms 1004 KB Output is correct
58 Correct 408 ms 876 KB Output is correct
59 Correct 534 ms 1004 KB Output is correct
60 Correct 384 ms 1004 KB Output is correct
61 Correct 5 ms 364 KB Output is correct
62 Correct 52 ms 748 KB Output is correct
63 Correct 181 ms 620 KB Output is correct
64 Correct 88 ms 620 KB Output is correct
65 Correct 163 ms 748 KB Output is correct
66 Correct 249 ms 1004 KB Output is correct
67 Correct 328 ms 1004 KB Output is correct
68 Correct 705 ms 1004 KB Output is correct
69 Correct 323 ms 876 KB Output is correct