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("O2")
#include <bits/stdc++.h>
#ifdef DEBUG
#include "debug.hpp"
#endif
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define rep(i, N) for(int i = 0; i < (N); ++i)
#define rrep(i, N) for(int i = (N) - 1; i >= 0; --i)
#define rep1(i, N) for(int i = 1; i <= (N); ++i)
#define rep2(i, s, e) for(int i = (s); i <= (e); ++i)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#ifdef DEBUG
#define debug(x...) { \
++dbg::depth; \
string dbg_vals = dbg::to_string(x); \
--dbg::depth; \
dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
}
#define light_debug(x) { \
dbg::light = true; \
dbg::dout << __func__ << ":" << __LINE__; \
dbg::dout << " " << #x << " = " << x << endl; \
dbg::light = false; \
}
#else
#define debug(x...) 42
#define light_debug(x) 42
#endif
using ll = long long;
template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }
template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef DEBUG
freopen("debug", "w", stderr);
#endif
constexpr int MAX_BITS{50};
int N, A, B; cin >> N >> A >> B;
vector<long long> Y(N + 1); rep1(i, N) cin >> Y[i];
partial_sum(all(Y), Y.begin());
long long mask = (2LL << MAX_BITS) - 1;
if(A > 1) {
for(int b = MAX_BITS; b >= 0; --b) {
mask ^= 1LL << b;
vector<vector<bool>> dp(N + 1, vector<bool>(N + 1));
dp[0][0] = true;
rep1(i, N) {
dp[i][1] = (mask | Y[i]) == mask;
rep2(k, 2, i)
rep2(j, k - 1, i)
dp[i][k] = dp[i][k] ||
(dp[j][k - 1] && (mask | (Y[i] - Y[j])) == mask);
}
bool possible = false;
rep2(i, A, B) possible |= dp[N][i];
debug(b, possible);
if(!possible) mask ^= 1LL << b;
}
} else {
for(int b = MAX_BITS; b >= 0; --b) {
mask ^= 1LL << b;
vector<int> dp(N + 1, N + 1);
dp[0] = 0;
rep1(i, N)
rep(j, i)
if((mask | (Y[i] - Y[j])) == mask)
ckmin(dp[i], dp[j] + 1);
debug(dp);
if(dp[N] > B) mask ^= 1LL << b;
}
}
cout << mask << '\n';
#ifdef DEBUG
dbg::dout << "\nExecution time: " << clock() * 1000 / CLOCKS_PER_SEC << "ms" << endl;
#endif
return 0;
}
Compilation message (stderr)
sculpture.cpp: In function 'int main()':
sculpture.cpp:35:29: warning: statement has no effect [-Wunused-value]
35 | #define debug(x...) 42
| ^~
sculpture.cpp:79:13: note: in expansion of macro 'debug'
79 | debug(b, possible);
| ^~~~~
sculpture.cpp:35:29: warning: statement has no effect [-Wunused-value]
35 | #define debug(x...) 42
| ^~
sculpture.cpp:92:13: note: in expansion of macro 'debug'
92 | debug(dp);
| ^~~~~
# | 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... |