| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 846238 | vjudge1 | Bali Sculptures (APIO15_sculpture) | C++17 | 67 ms | 596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pll pair <long long, long long>
#define fi first
#define se second
using namespace std;
#define task "code"
#define all(s) s.begin(), s.end()
typedef long long ll;
const int ar = 2e3+2;
const ll mod = 998244353;
const ll oo = 1e18;
int n, p, q;
ll sum[ar];
bool f[101][101];
ll dp[ar];
void sub1() {
ll ans = 0;
for(int bit = 40; bit >= 0; --bit) {
memset(f, 0, sizeof f);
f[0][0] = 1;
ll tmp = ans | (1ll << bit);
for(int j = 1; j <= q; ++j)
for(int i = j; i <= n; ++i)
for(int k = 1; k <= i; ++k) {
ll tong = sum[i] - sum[k - 1];
f[i][j] |= (f[k - 1][j - 1] && ((tong & tmp) == 0));
}
for(int i = p; i <= q; ++i) if(f[n][i]) {
ans |= (1ll << bit);
break;
}
}
ll res = 0;
for(int i = 0 ; i <= 40 ; ++i)
if (ans >> i & 1 ^ 1) res |= (1ll << i);
cout << res;
}
void sub2() {
ll ans = 0;
for(int bit = 40; bit >= 0; --bit) {
memset(dp, 0x3f, sizeof dp);
dp[0] = 0;
ll tmp = ans | (1ll << bit);
for(int i = 1; i <= n; ++i)
for(int k = 1; k <= i; ++k) {
ll tong = sum[i] - sum[k - 1];
if((tong & tmp) == 0 && dp[k - 1] < oo)
dp[i] = min(dp[i], dp[k - 1] + 1);
}
if(dp[n] <= q) ans = tmp;
}
ll res = 0;
for(int i = 0 ; i <= 40 ; ++i)
if (ans >> i & 1 ^ 1) res |= (1ll << i);
cout << res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n >> p >> q;
for(int i = 1; i <= n; ++i) {
int a;
cin >> a;
sum[i] = sum[i - 1] + a;
}
if(p != 1 && n <= 100)
sub1();
else
sub2();
return 0;
}
Compilation message (stderr)
| # | 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... | ||||
