#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2000 + 7;
int n, mn, mx;
ll a[N];
bool good[N][N], ok[N][N];
bool okapi(ll x, ll cur, int bit) {
ll y = x % (1LL << (bit + 1));
return (x - y == cur && y < (1LL << bit));
}
bool valid(ll cur, int bit) {
ll val = (1LL << bit);
for (int i = 1; i <= n; i++) {
ll sum = 0;
for (int j = i; j <= n; j++) {
sum += a[j];
good[i][j] = okapi(sum, cur, bit);
}
}
for (int i = 0; i <= n; i++)
for (int j = 0; j <= mx; j++)
ok[i][j] = 0;
ok[0][0] = 1;
for (int i = 0; i < n; i++)
for (int c = 0; c < mx; c++)
if (ok[i][c])
for (int j = i + 1; j <= n; j++)
if (good[i + 1][j])
ok[j][c + 1] = 1;
for (int c = mn; c <= mx; c++)
if (ok[n][c])
return 1;
return 0;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
///freopen ("input", "r", stdin);
cin >> n >> mn >> mx;
for (int i = 1; i <= n; i++)
cin >> a[i];
if (n <= 100) {
ll sum = 0;
for (int i = 1; i <= n; i++)
sum += a[i];
ll mask = 0;
for (int k = log2(sum); k >= 0; k--)
if (valid(mask, k) == 0)
mask += (1LL << k);
cout << mask << "\n";
return 0;
}
return 0;
}
Compilation message
sculpture.cpp: In function 'bool valid(ll, int)':
sculpture.cpp:17:12: warning: unused variable 'val' [-Wunused-variable]
ll val = (1LL << bit);
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |