이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
sculpture.cpp: In function 'bool valid(ll, int)':
sculpture.cpp:17:12: warning: unused variable 'val' [-Wunused-variable]
ll val = (1LL << bit);
^~~| # | 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... |