답안 #767738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
767738 2023-06-27T06:26:05 Z Tob Bali Sculptures (APIO15_sculpture) C++14
0 / 100
1 ms 308 KB
#include <bits/stdc++.h>

#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef pair <ll, ll> pii;

const int N = 2e3 + 7;

ll n, a, b;
ll aa[N], ps[N], dp[N][N], dp2[N];

ll Sum(ll x, ll y) {
	if (!x) return ps[y];
	return ps[y] - ps[x-1] + 1;
}

int main () {
	cin >> n >> a >> b;
	
	for (int i = 1; i <= n; i++) {
		cin >> aa[i];
		ps[i] = ps[i-1] + aa[i];
	}
	
	if (a > 1) {
		ll cur = 0;
		for (int i = 41; i >= 0; i--) {
			memset(dp, 0, sizeof dp);
			dp[0][0] = 1;
			for (int j = 1; j <= n; j++) {
				for (int k = 1; k <= j; k++) {
					for (int l = 1; l <= b; l++) {
						if (((Sum(k, j) >> i) & (cur >> i)) == (Sum(k, j) >> i)) dp[j][l] |= dp[k-1][l-1];
					}
				}
			}
			int ok = 0;
			for (int i = a; i <= b; i++) ok |= dp[n][i];
			if (!ok) cur |= (1LL << i);
		}
		cout << cur;
	}
	else {
		ll cur = 0;
		for (int i = 41; i >= 0; i--) {
			for (int j = 1; j <= n; j++) dp2[j] = 1e18;
			for (int j = 1; j <= n; j++) {
				for (int k = 1; k <= j; k++) {
					if (((Sum(k, j) >> i) & (cur >> i)) == (Sum(k, j) >> i)) dp2[j] = min(dp2[j], dp2[k-1]+1);
				}
			}
			int ok = 0;
			if (dp2[n] > b) cur |= (1LL << i);
		}
		cout << cur;
	}

	return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:59:8: warning: unused variable 'ok' [-Wunused-variable]
   59 |    int ok = 0;
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Incorrect 0 ms 304 KB Output isn't correct
3 Halted 0 ms 0 KB -