답안 #549124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
549124 2022-04-15T08:46:47 Z Duy_e Bali Sculptures (APIO15_sculpture) C++14
21 / 100
1 ms 296 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<ll, ll>
#define st first
#define nd second
#define file "test"
using namespace std;
const long long INF = 1e18;
const long long N = 2e3 + 5;

ll n, a[N], A, B, f[N], dp[N];

ll get(int l, int r) {
	return f[r] - f[l - 1];
}

bool solve(ll x, ll pre) {
	int cnt = 1;
	ll sum = 0;

	for (int i = 0; i <= n; i ++) dp[i] = n + 1;
	dp[0] = 0;

	for (int i = 0; i <= n; i ++) {
		for (int j = i + 1; j <= n; j ++)
			if ((get(i + 1, j) | pre) <= x)
				dp[j] = min(dp[j], dp[i] + 1);
	}

	// for (int i = 1; i <= n; i ++) {
	// 	sum += a[i];
	// 	if ((sum | pre) > x) {
	// 		sum = a[i];
	// 		cnt ++;

	// 		if ((sum | pre) > x) return false;
	// 	}
	// }

	return dp[n] <= B;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// 	freopen(file".inp","r",stdin); freopen(file".out","w",stdout);
	// #endif
	
	cin >> n >> A >> B;
	for (int i = 1; i <= n; i ++)
		cin >> a[i], f[i] = f[i - 1] + a[i];
	
	ll ans = 0;

	int last = 45;

	for (int i = 0; i < 45; i ++) {
		for (int j = 0; j < last; j ++) {
			ll tmp = ans | ((1ll << (j + 1)) - 1); 
			if (solve(ans, ans)) {i = 60; break;};
			if (solve(tmp, ans)) {
				last = j;
				ans |= 1 << j;
				// cout << j << ' ' << ans << '\n';
			}
		}
	} 

	cout << ans;

	return 0;
}	
/**  /\_/\
    (= ._.)
    / >🍵 \>🍮

statement:
	given n number (n <= 100) a[i] <= 1e9
	and two integer A, B;
	find the way to split the initial array into x consecutive subarray
	such that the sum of or of every subarray is minimum

	x should be any number between A, B -> A <= x <= B

bitwise or operation

OR minimum -> msb is lowest

**/

Compilation message

sculpture.cpp: In function 'bool solve(long long int, long long int)':
sculpture.cpp:18:6: warning: unused variable 'cnt' [-Wunused-variable]
   18 |  int cnt = 1;
      |      ^~~
sculpture.cpp:19:5: warning: unused variable 'sum' [-Wunused-variable]
   19 |  ll sum = 0;
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 1 ms 212 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 1 ms 212 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 296 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Incorrect 1 ms 212 KB Output isn't correct
18 Halted 0 ms 0 KB -