이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#define ll long long
using namespace std;
ll n, a, b, f, z, mn, x, y, A[2000], ps[2000], MX[2000][2000], dp[2000][2000];
void AOne() {
for (int t=40; t>=0; --t) {
z = (1LL << t);
for (int i=0; i<n; ++i) {
dp[i][0] = 1e18;
if ((ps[i] & x) == 0 && (ps[i] & z) == 0) dp[i][0] = 1;
for (int k=0; k<i; ++k) {
y = ps[i]-ps[k];
if ((y & x) == 0 && (y & z) == 0) {
dp[i][0] = min(dp[i][0], dp[k][0]+1);
}
}
}
if (dp[n-1][0] <= b) x += z;
else f += z;
}
cout << f << '\n';
}
void ANot() {
for (int t=40; t>=0; --t) {
z = (1LL << t);
for (int i=0; i<n; ++i) {
for (int j=0; j<n; ++j) {
dp[i][j] = 1e18;
if (!j && (ps[i] & x) == 0) dp[i][j] = ps[i] & z;
if (!j) continue;
for (int k=0; k<i; ++k) {
y = ps[i]-ps[k];
if (dp[k][j-1] != 1e18 && (y & x) == 0) {
dp[i][j] = min(dp[i][j], dp[k][j-1] | (y & z));
}
}
}
}
mn = 1e18;
for (int i=a-1; i<b; ++i) {
mn = min(mn, dp[n-1][i]);
}
if (!mn) x += z;
else f += z;
}
cout << f << '\n';
}
int main() {
cin >> n >> a >> b;
for (int i=0; i<n; ++i) {
cin >> A[i];
if (!i) ps[i] = A[i];
else ps[i] = ps[i-1]+A[i];
}
if (a == 1) AOne();
else ANot();
}
| # | 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... |