이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
long long arr[2005];
long long prefix[2005];
vector<vector<int>> v;
long long res = 0;
inline long long sum(int i, int j){
if(i > j) swap(i, j);
return prefix[j]-prefix[i-1];
}
bool check(vector<vector<int>> &tmp){
if(n>100){
int dp[n+1]; fill(dp, dp+n+1, n+1);
dp[0] = 0;
for(int i = 1; i<=n; i++){
for(auto j : tmp[i]) dp[i] = min(dp[j-1]+1, dp[i]);
}
if(dp[n] == -1 || dp[n] > b) return false;
return 1;
}
bitset<105> dp[n+1];
dp[0].reset();
dp[0].set(0);
for(int i = 1; i<=n; i++){
dp[i].reset();
for(int j : tmp[i]) dp[i] |= (dp[j-1]<<1);
}
for(int i = a; i<=b; i++){
if(dp[n].test(i)) return 1;
}
return 0;
}
int main(){
// freopen("a.in", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> b;
for(int i = 1; i<=n; i++) cin >> arr[i];
prefix[0] = 0;
for(int i = 1; i<=n; i++) prefix[i] = prefix[i-1]+arr[i];
v.resize(n+1);
for(int i = 1; i<=n; i++){
for(int j = i; j<=n; j++){
v[j].push_back(i);
}
}
for(int m = 60; m>=0; m--){
vector<vector<int>> tmp;
tmp.resize(n+1);
for(int i = 1; i<=n; i++){
for(auto &x : v[i]){
if(sum(x, i)&(1ll<<m)) continue;
else tmp[i].push_back(x);
}
}
if(check(tmp)){
v = tmp;
}
else res += 1ll<<m;
}
cout << res << endl;
}
# | 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... |