This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma,bmi,bmi2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n, A, B;
ull x[2001], pref[2001];
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> A >> B;
for (int i = 1; i <= n; i++)
cin >> x[i];
pref[0] = 0;
for (int i = 1; i <= n; i++)
pref[i] = pref[i-1] + x[i];
ull mask = 0;
vector<pair<int,int>> segments = {{1, n}};
for (ull y = 1LL << 63; y; y >>= 1)
{
vector<pair<int,int>> new_segments;
bool possible = true;
for (auto [L, R] : segments)
{
for (int l = L; l <= R; l++)
{
possible = false;
for (int r = R; r >= l; r--)
if (((pref[r] - pref[l-1]) & (mask | y)) == 0)
{
new_segments.push_back({l, r});
l = r;
possible = true;
break;
}
if (!possible) break;
}
if (!possible) break;
}
if (possible && new_segments.size() <= B)
segments = new_segments, mask |= y;
}
/*
for (auto [l, r] : segments)
cout << "(" << l << ", " << r << ") ";
cout << '\n';
*/
cout << (~mask) << '\n';
return 0;
}
Compilation message (stderr)
sculpture.cpp: In function 'int main()':
sculpture.cpp:46:45: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | if (possible && new_segments.size() <= B)
| ~~~~~~~~~~~~~~~~~~~~^~~~
# | 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... |