#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define task "kbsiudthw"
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 2277;
int n, A, B, a[2005], ans, nAns;
int dp[2005];
bool check(int x){
int limit = (1ll<<x);
dp[0] = 0;
FOR (i, 1, n){
dp[i] = INF;
FORD(j, i-1, 0){
int s = (a[i] - a[j]);
if ((s & nAns) == 0) dp[i] = min(dp[i], dp[j]+1);
}
}
return dp[n] <= B ;
}
bool dp2[2005][2005];
bool check2(int x){
memset(dp2, 0, sizeof dp2);
dp2[0][0] = 1;
FOR (i, 1, n){
FOR (j, 1, i) FORD(k, i-1, 0){
int s = a[i] - a[k];
if ((s & nAns) == 0) {
dp2[i][j] |= dp2[k][j-1];
}
}
}
bool ans = 0;
FOR (i, A, B) ans |= dp2[n][i];
return ans;
}
void solve(){
FORD(i, 40, 0){
nAns += (1ll<<i);
if (!check2(i)){
ans += (1ll<<i);
nAns -= (1ll<<i);
}
}
cout << ans ;
}
signed 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 >> A >> B;
FOR (i, 1, n) cin >> a[i], a[i] += a[i-1];
if (n <= 100){
solve();
return 0;
}
FORD(i, 40, 0){
nAns += (1ll<<i);
if (!check(i)){
ans += (1ll<<i);
nAns -= (1ll<<i);
}
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sculpture.cpp: In function 'int main()':
sculpture.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |