이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
}
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);
}
}
}
if (dp2[n] > b) cur |= (1LL << i);
}
cout << cur;
}
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... |