이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define submask(i, j) (((i) ^ (j)) == ((i) - (j)))
#define maxn 100005
using namespace std;
typedef long long ll;
int n, A, B;
ll f[maxn];
bool check(ll mask, int index) {
if (A == 1) {
vector < int > d(n + 1, B + 1);
d[0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 0; j < i; ++j)
if (submask(mask >> index, (f[i] - f[j]) >> index))
d[i] = min(d[i], d[j] + 1);
return d[n] <= B;
}
else {
vector < vector < int > > d(n + 1, vector < int >(n + 1, 0));
d[0][0] = 1;
for (int i = 1; i <= n; ++i)
for (int j = 0; j < i; ++j)
if (submask(mask >> index, (f[i] - f[j]) >> index))
for (int k = 1; k <= n; ++k)
d[i][k] |= d[j][k - 1];
for (int i = A; i <= B; ++i)
if (d[n][i])
return 1;
return 0;
}
}
int main() {
#define TASK "ABC"
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> A >> B;
for (int i = 1; i <= n; ++i) {
cin >> f[i];
f[i] += f[i - 1];
}
ll ans = 0;
for (int i = 50; i >= 0; --i)
if (!check(ans, i)) ans += (1ll << i);
cout << ans;
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... |