이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 2000;
const int BITS = 41;
int N, Xmin, Xmax;
int V[N_MAX + 2];
bool can[N_MAX + 2][N_MAX + 2];
bool makePrefSlow (ll pref, int suffLen) {
fill(can[0] + 1, can[0] + Xmax + 1, false);
can[0][0] = true;
for (int i = 1; i <= N; i++) {
can[i][0] = false;
for (int x = 1; x <= Xmax; x++) {
can[i][x] = false;
ll sum = 0;
for (int j = i; j >= 1; j--) {
sum += V[j];
if ((sum & ~pref) >= ((ll) 1 << suffLen)) {
continue;
}
if (can[j - 1][x - 1] == true) {
can[i][x] = true;
break;
}
}
}
}
for (int x = Xmin; x <= Xmax; x++) {
if (can[N][x] == true) {
return true;
}
}
return false;
}
int minX[N_MAX + 2];
bool makePrefFast (ll pref, int suffLen) {
minX[0] = 0;
for (int i = 1; i <= N; i++) {
minX[i] = Xmax + 1;
ll sum = 0;
for (int j = i; j >= 1; j--) {
sum += V[j];
if ((sum & ~pref) >= ((ll) 1 << suffLen)) {
continue;
}
minX[i] = min(minX[i], minX[j - 1] + 1);
}
}
return (minX[N] <= Xmax);
}
bool makePref (ll pref, int suffLen) {
return (Xmin == 1 ? makePrefFast(pref, suffLen) : makePrefSlow(pref, suffLen));
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> Xmin >> Xmax;
for (int i = 1; i <= N; i++) {
cin >> V[i];
}
ll answer = 0;
for (int bit = BITS - 1; bit >= 0; bit--) {
if (makePref(answer, bit) == false) {
answer |= ((ll) 1 << bit);
}
}
cout << answer << "\n";
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... |