이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)
#define WTF cout << "WTF" << endl
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, PII> PPI;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
const int N = 2000 + 7;
const int INF = 1e9 + 7;
const int LOG = 45;
int n, a, b;
int ns[N], mem[N];
bool dp[N][N];
void case1() {
LL num = (1LL << LOG) - 1;
R0F(i, LOG) {
num ^= (1LL << i);
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
FOR(i, 1, n + 1) FOR(j, 1, i + 1) {
LL sum = 0;
ROF(k, 1, i + 1) {
sum += ns[k];
if ((sum & num) == sum) dp[i][j] |= dp[k - 1][j - 1];
}
}
bool possible = 0;
FOR(i, a, b + 1) possible |= dp[n][i];
if (!possible) num ^= (1LL << i);
}
cout << num << endl;
return;
}
void case2() {
LL num = (1LL << LOG) - 1;
R0F(i, LOG) {
num ^= (1LL << i);
fill(mem, mem + n + 1, INF);
mem[0] = 0;
FOR(i, 1, n + 1) {
LL sum = 0;
ROF(j, 1, i + 1) {
sum += ns[j];
if ((sum & num) == sum)
mem[i] = min(mem[i], mem[j - 1] + 1);
}
}
if (mem[n] > b) num ^= (1LL << i);
}
cout << num;
}
int main() {
IOS;
cin >> n >> a >> b;
FOR(i, 1, n + 1) cin >> ns[i];
if (n <= 100) case1();
else case2();
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... |