Submission #978765

# Submission time Handle Problem Language Result Execution time Memory
978765 2024-05-09T15:36:02 Z SmuggingSpun Bali Sculptures (APIO15_sculpture) C++14
100 / 100
70 ms 860 KB
#include<bits/stdc++.h>
#define taskname "sculpture"
using namespace std;
typedef long long ll;
const int INF = 1e9;
template<class T>void minimize(T& a, T b){
	if(a > b){
		a = b;
	}
}
int n, a, b;
vector<int>y;
namespace sub1{
	void solve(){
		ll ans = LLONG_MAX;
		for(int mask = (1 << n) - 2; mask > -1; mask -= 2){
			int cnt_1 = __builtin_popcount(mask) + 1;
			if(a <= cnt_1 && cnt_1 <= b){
				ll value = 0, sum = 0;
				for(int i = 0; i < n; ){
					if(1 << i & mask){
						value |= sum;
						sum = 0;
					}
					sum += y[++i];
				}
				minimize(ans, value | sum);
			}
		}
		cout << ans;
	}
}
namespace sub2{
	const int LIM = 512;
	const int lim = 105;
	bitset<LIM>dp[2][lim];
	void solve(){
		bool cur = true, pre = false;
		int ans = LIM;
		for(int i = 0; i <= n; i++){
			dp[cur][i].reset();
		}
		dp[cur][n + 1].set(0);
		for(int i = 1; i <= b; i++){
			swap(cur, pre);
			for(int j = 0; j <= n; j++){
				dp[cur][j].reset();
			}
			for(int j = 1; j <= n; j++){
				for(int k = j, sum = 0; k <= n; k++){
					sum += y[k];
					for(int value = 0; value < LIM; value++){
						if(dp[pre][k + 1].test(value)){
							dp[cur][j].set(value | sum);
						}
					}
				}
			}
			if(i >= a){
				for(int j = 0; j < ans; j++){
					if(dp[cur][1].test(j)){
						ans = j;
						break;
					}
				}
			}
		}
		cout << ans << "\n";
	}
}
namespace sub3{
	const int LIM = 2048;
	void solve(){
		for(int i = 1; i < LIM; i++){
			vector<int>dp(n + 2, INF);
			dp[n + 1] = 0;
			for(int j = n; j > 0; j--){
				for(int k = j, sum = 0; k <= n; k++){
					if(((sum += y[k]) & i) == sum){
						minimize(dp[j], dp[k + 1] + 1);
					}
				}
			}
			if(dp[1] <= b){
				cout << i;
				break;
			}
		}
	}
}
namespace sub4{
	const int lim = 105;
	bitset<lim>dp[lim];
	void solve(){
		dp[n + 1].set(0);
		ll ans = 0;
		for(int i = 36; i > -1; i--){
			for(int j = 1; j <= n; j++){
				dp[j].reset();
			}
			for(int j = n; j > 0; j--){
				ll sum = 0;
				for(int k = j; k <= n; k++){
					if(((sum += y[k]) & ~ans) < (1LL << i)){
						for(int t = 0; t < n; t++){
							if(dp[k + 1].test(t)){
								dp[j].set(t + 1);
							}
						}
					}
				}
			}
			ans |= 1LL << i;
			for(int j = a; j <= b; j++){
				if(dp[1].test(j)){
					ans ^= 1LL << i;
					break;
				}
			}
		}
		cout << ans;
	}
}
namespace sub5{
	const int lim = 2e3 + 5;
	int dp[lim];
	void solve(){
		ll ans = dp[n + 1] = 0;
		for(int i = 44; i > -1; i--){
			for(int j = n; j > 0; j--){
				ll sum = 0;
				dp[j] = INF;
				for(int k = j; k <= n; k++){
					if(((sum += y[k]) & ~ans) < (1LL << i)){
						minimize(dp[j], dp[k + 1] + 1);
					}
				}
			}
			if(dp[1] > b){
				ans |= 1LL << i;
			}
		}
		cout << ans;
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> n >> a >> b;
	y.resize(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> y[i];
	}
	if(n <= 20){
		sub1::solve();
	}
	else if(n <= 50 && *max_element(y.begin() + 1, y.end()) <= 10){
		sub2::solve();
	}
	else if(n <= 100 && *max_element(y.begin() + 1, y.end()) <= 20 && a == 1){
		sub3::solve();
	}
	else if(n <= 100){
		sub4::solve();
	}
	else{
		sub5::solve();
	}
}

Compilation message

sculpture.cpp: In function 'void sub3::solve()':
sculpture.cpp:79:15: warning: operation on 'sum' may be undefined [-Wsequence-point]
   79 |      if(((sum += y[k]) & i) == sum){
      |          ~~~~~^~~~~~~~
sculpture.cpp:79:15: warning: operation on 'sum' may be undefined [-Wsequence-point]
sculpture.cpp: In function 'int main()':
sculpture.cpp:149:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  149 |   freopen(taskname".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 33 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 30 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 29 ms 348 KB Output is correct
34 Correct 33 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 33 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 33 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 4 ms 460 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 29 ms 348 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 8 ms 348 KB Output is correct
31 Correct 14 ms 348 KB Output is correct
32 Correct 14 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 13 ms 348 KB Output is correct
35 Correct 14 ms 480 KB Output is correct
36 Correct 7 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 34 ms 348 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 9 ms 596 KB Output is correct
18 Correct 14 ms 348 KB Output is correct
19 Correct 13 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 13 ms 472 KB Output is correct
22 Correct 12 ms 468 KB Output is correct
23 Correct 8 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 8 ms 456 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 33 ms 452 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Correct 4 ms 348 KB Output is correct
23 Correct 4 ms 500 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 6 ms 348 KB Output is correct
26 Correct 29 ms 456 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 29 ms 348 KB Output is correct
34 Correct 35 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 33 ms 348 KB Output is correct
37 Correct 3 ms 468 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 9 ms 348 KB Output is correct
41 Correct 14 ms 468 KB Output is correct
42 Correct 14 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 13 ms 348 KB Output is correct
45 Correct 12 ms 348 KB Output is correct
46 Correct 7 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 8 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 3 ms 348 KB Output is correct
60 Correct 2 ms 348 KB Output is correct
61 Correct 3 ms 348 KB Output is correct
62 Correct 5 ms 344 KB Output is correct
63 Correct 6 ms 860 KB Output is correct
64 Correct 17 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 2 ms 344 KB Output is correct
68 Correct 3 ms 348 KB Output is correct
69 Correct 3 ms 460 KB Output is correct
70 Correct 2 ms 348 KB Output is correct
71 Correct 3 ms 348 KB Output is correct
72 Correct 5 ms 464 KB Output is correct
73 Correct 5 ms 348 KB Output is correct
74 Correct 5 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 2 ms 456 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 33 ms 460 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 4 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 29 ms 348 KB Output is correct
21 Correct 33 ms 456 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 33 ms 436 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 11 ms 600 KB Output is correct
28 Correct 14 ms 348 KB Output is correct
29 Correct 13 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 13 ms 472 KB Output is correct
32 Correct 11 ms 600 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 8 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 432 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 3 ms 348 KB Output is correct
46 Correct 3 ms 348 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 3 ms 348 KB Output is correct
49 Correct 5 ms 348 KB Output is correct
50 Correct 5 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 6 ms 348 KB Output is correct
53 Correct 9 ms 348 KB Output is correct
54 Correct 18 ms 480 KB Output is correct
55 Correct 16 ms 344 KB Output is correct
56 Correct 62 ms 348 KB Output is correct
57 Correct 60 ms 344 KB Output is correct
58 Correct 59 ms 344 KB Output is correct
59 Correct 64 ms 476 KB Output is correct
60 Correct 63 ms 492 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 10 ms 348 KB Output is correct
63 Correct 19 ms 348 KB Output is correct
64 Correct 16 ms 348 KB Output is correct
65 Correct 31 ms 348 KB Output is correct
66 Correct 46 ms 344 KB Output is correct
67 Correct 60 ms 344 KB Output is correct
68 Correct 70 ms 348 KB Output is correct
69 Correct 59 ms 472 KB Output is correct