이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define X first
#define Y second
#define sep ' '
#define endl '\n'
#define debug(x) cerr << #x << ": " << x << endl;
const ll MAXN = 2e3 + 10;
const ll LOG = 50;
ll A[MAXN], n, a, b;
bool dp[MAXN][MAXN];
int dp2[MAXN];
inline bool check2(ll mask) {
for (int i = 1; i <= n; i++) {
dp2[i] = MAXN;
ll s = 0;
for (int j = i; j > 0; j--) {
s += A[j];
if (!(s & mask))
dp2[i] = min(dp2[i], dp2[j - 1] + 1);
}
}
return dp2[n] <= b;
}
inline bool check(ll mask) {
if (a == 1) return check2(mask);
memset(dp, false, sizeof dp);
dp[0][0] = true;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
ll s = 0;
for (int k = i; k > 0; k--) {
s += A[k];
if (!(s & mask))
dp[i][j] |= dp[k - 1][j - 1];
}
}
}
return count(dp[n] + a, dp[n] + b + 1, true);
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> A[i];
ll ans = 0, mask = 0;
for (int i = LOG - 1; i >= 0; i--) {
mask ^= (1ll << i);
if (!check(mask)) {
mask ^= (1ll << i);
ans ^= (1ll << i);
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |