이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18, N = 2000 + 10;
int n, a, b;
vector<int> v(N);
bitset<N> mask[N], dp[N];
bool check(ll exp)
{
bitset<N> dp[1 + b];
for(int i = 0; i <= b; i ++)
dp[i].reset();
dp[0][0] = 1;
for(int i = 1; i <= n; i ++)
{
bitset<N> mymask;
mymask.reset();
ll sm = 0;
for(int j = i; j <= n; j ++)
{
sm += v[j];
if(sm & (~exp)) continue;
mymask[j] = 1;
}
mask[i] = mymask;
}
for(int j = 0; j < b; j ++)
for(int i = 0; i < n; i ++)
{
if(dp[j][i] == 0) continue;
dp[j + 1] |= mask[i + 1];
}
bool ans = false;
for(int i = a; i <= b; i ++) ans |= dp[i][n];
return ans;
}
int main()
{
cin >> n >> a >> b;
for(int i = 1; i <= n; i ++)
cin >> v[i];
ll ans = 0;
for(int i : v) ans += i;
int b = 64 - __builtin_clzll(ans);
ans = (1LL << b) - 1;
for(int i = 63; i >= 0; i --)
{
if((1LL << i) & ans)
{
ans -= (1LL << i);
if(!check(ans))
ans += (1LL << i);
}
}
cout << ans << endl;
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... |