Submission #671884

# Submission time Handle Problem Language Result Execution time Memory
671884 2022-12-14T07:59:10 Z Dan4Life Bali Sculptures (APIO15_sculpture) C++17
16 / 100
34 ms 22348 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = (int)53;
const ll LINF = (ll)1e18;
int n, A, B;
ll a[maxn], pre[maxn]; ll ans=LINF;
bool dp[maxn][maxn][25][1028];
 
void recur(int pos, int lpos, int knum, int Or){
	if(dp[pos][lpos][knum][Or]) return;
	dp[pos][lpos][knum][Or]=1;
	if(pos==n+1) return;
	if(pos!=n) recur(pos+1, lpos, knum, Or);
	recur(pos+1, pos, knum+1, Or|(pre[pos]-pre[lpos]));
}

int32_t main() {
	cin >> n >> A >> B;
	for(int i = 0; i < n; i++) cin >> a[i], pre[i+1]=pre[i]+a[i];
 
	if(n<=20){
		for(int mask = 0; mask < (1<<n); mask++){
			int num = __builtin_popcount(mask);
			if(num<A or num>B or !(mask&(1<<(n-1)))) continue;
			ll Or = 0, sum = 0;
			for(int i = 0; i < n; i++){
				if(mask&(1<<i)) sum+=a[i], Or|=sum, sum=0;
				else sum+=a[i];
			}
			ans = min(ans, Or);
		}
	}
	if(n<=50){
		recur(1,0,1,0);
		for(int i = A+1; i <= B+1; i++)
			for(int k = 0; k < 1028; k++)
				if(dp[n+1][n][B+1][k]) ans = min(ans, (ll)k);
	}
	if(n<=100 and A==1){
		const int mxOR = 2048;
		int dp[n+1][mxOR];
		for(int i = 0; i <= n; i++)
			fill(dp[i], dp[i]+mxOR, n+1);
		dp[0][0]=0;
		for(int i = 0; i < n; i++)
			for(int j = 0; j < mxOR; j++)
				for(int k = i+1; k <= n; k++)
					dp[k][j|(pre[k]-pre[i])]=min(dp[k][j|(pre[k]-pre[i])], dp[i][j]+1);
		for(int j = 0; j < mxOR; j++)
			if(dp[n][j]<=B) ans=min(ans,(ll)j);
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 772 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 3 ms 1740 KB Output is correct
8 Correct 6 ms 2516 KB Output is correct
9 Correct 5 ms 2516 KB Output is correct
10 Correct 6 ms 2516 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 5 ms 2516 KB Output is correct
13 Correct 32 ms 2484 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1620 KB Output is correct
21 Correct 7 ms 2260 KB Output is correct
22 Correct 6 ms 2260 KB Output is correct
23 Correct 6 ms 2260 KB Output is correct
24 Correct 4 ms 2260 KB Output is correct
25 Correct 7 ms 2260 KB Output is correct
26 Correct 30 ms 2260 KB Output is correct
27 Runtime error 2 ms 464 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 4 ms 1364 KB Output is correct
7 Correct 3 ms 1748 KB Output is correct
8 Correct 6 ms 2476 KB Output is correct
9 Correct 5 ms 2516 KB Output is correct
10 Correct 5 ms 2516 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 5 ms 2516 KB Output is correct
13 Correct 32 ms 2472 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 1256 KB Output is correct
20 Correct 1 ms 1620 KB Output is correct
21 Correct 6 ms 2260 KB Output is correct
22 Correct 6 ms 2260 KB Output is correct
23 Correct 7 ms 2260 KB Output is correct
24 Correct 4 ms 2260 KB Output is correct
25 Correct 7 ms 2348 KB Output is correct
26 Correct 29 ms 2344 KB Output is correct
27 Correct 4 ms 2772 KB Output is correct
28 Correct 6 ms 4180 KB Output is correct
29 Correct 14 ms 11504 KB Output is correct
30 Correct 17 ms 14676 KB Output is correct
31 Correct 28 ms 22232 KB Output is correct
32 Correct 26 ms 22228 KB Output is correct
33 Correct 25 ms 22220 KB Output is correct
34 Correct 31 ms 22348 KB Output is correct
35 Correct 27 ms 22292 KB Output is correct
36 Correct 30 ms 22220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 2 ms 1748 KB Output is correct
8 Correct 6 ms 2516 KB Output is correct
9 Correct 6 ms 2516 KB Output is correct
10 Correct 5 ms 2532 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 5 ms 2516 KB Output is correct
13 Correct 32 ms 2472 KB Output is correct
14 Correct 4 ms 2772 KB Output is correct
15 Correct 5 ms 4200 KB Output is correct
16 Correct 14 ms 11552 KB Output is correct
17 Correct 17 ms 14716 KB Output is correct
18 Correct 28 ms 22248 KB Output is correct
19 Correct 26 ms 22304 KB Output is correct
20 Correct 26 ms 22228 KB Output is correct
21 Correct 26 ms 22228 KB Output is correct
22 Correct 26 ms 22260 KB Output is correct
23 Correct 28 ms 22328 KB Output is correct
24 Correct 10 ms 596 KB Output is correct
25 Incorrect 2 ms 1620 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 3 ms 1748 KB Output is correct
8 Correct 5 ms 2516 KB Output is correct
9 Correct 6 ms 2516 KB Output is correct
10 Correct 6 ms 2516 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 5 ms 2520 KB Output is correct
13 Correct 32 ms 2468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1620 KB Output is correct
21 Correct 7 ms 2260 KB Output is correct
22 Correct 6 ms 2260 KB Output is correct
23 Correct 7 ms 2352 KB Output is correct
24 Correct 3 ms 2260 KB Output is correct
25 Correct 6 ms 2260 KB Output is correct
26 Correct 28 ms 2348 KB Output is correct
27 Runtime error 2 ms 468 KB Execution killed with signal 11
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 3 ms 1364 KB Output is correct
7 Correct 2 ms 1748 KB Output is correct
8 Correct 5 ms 2516 KB Output is correct
9 Correct 5 ms 2516 KB Output is correct
10 Correct 5 ms 2516 KB Output is correct
11 Correct 5 ms 2516 KB Output is correct
12 Correct 5 ms 2484 KB Output is correct
13 Correct 34 ms 2508 KB Output is correct
14 Runtime error 2 ms 432 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -