#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define ll long long
#define int long long
ll dp1[2000][2000], dp2[2001], arr[2000], n, a, b;
ll powfunc(int a) {
ll val = 1;
for (int i=0;i<a;i++) {
val *= 2;
}
return val;
}
bool solve(ll val) {
if (a != 1) {
} else {
for (int i=0;i<n+1;i++) {
dp2[i] = 1000000;
}
dp2[0] = 0;
for (int i=0;i<n;i++) {
int sum = 0;
for (int j=i;j>-1;j--) {
sum += arr[j];
if ((sum & val) == sum) dp2[i + 1] = min(dp2[i + 1], dp2[j] + 1);
}
}
//cout << val << '\n';
//for (int i=0;i<n+1;i++) {
// cout << dp2[i] << ' ';
//} cout << '\n';
if (dp2[n] > b) return false;
else return true;
}
}
int32_t main() {
cin >> n >> a >> b;
for (int i=0;i<n;i++) {
cin >> arr[i];
}
ll ans = powfunc(42) - 1;
for (int i=41;i>-1;i--) {
ans -= powfunc(i);
if (solve(ans)) continue;
else ans += powfunc(i);
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
sculpture.cpp: In function 'bool solve(long long int)':
sculpture.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
46 | }
| ^
# | 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... |