This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define FileName "test"
#define ll long long
#define ld long double
#define ull unsigned long long
#define Debug(x) cerr << #x << "is " << x << '\n';
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
//#define LuckyAurora
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
template<typename T> inline void Cin(T &x)
{
char c;
T sign = 1;
x = 0;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
if (c == '-') sign = -1;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
x *= sign;
}
template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');}
template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);}
template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);}
template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);}
const ll inf = (1ll << 50) - 1;
const int N = 2e3 + 7;
ll a[N];
int n, l, r;
void Enter()
{
cin >> n >> l >> r;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] += a[i - 1];
}
}
void Solve()
{
if(l == 1) {
ll res = inf;
for(int bit = 49; bit >= 0; --bit) {
vector<int> f(n + 1, n + 1);
f[0] = 0; res -= (1ll << bit);
for(int i = 1; i <= n; ++i) {
for(int j = 0; j < i; ++j)
if(((a[i] - a[j]) | res) == res) f[i] = min(f[i], f[j] + 1);
}
if(f[n] > r) res += (1ll << bit);
}
cout << res;
} else {
vector< vector<ll> > f;
f.resize(n + 1);
f[0].resize(n + 1, inf);
f[0][0] = 0;
for(int i = 1; i <= n; ++i) {
f[i].resize(n + 1, inf);
for(int j = 1; j <= r; ++j) {
for(int k = 0; k < i; ++k)
f[i][j] = min(f[i][j], f[k][j - 1] | (a[i] - a[k]));
}
}
ll res = inf;
for(int i = l; i <= r; ++i) res = min(res, f[n][i]);
cout << res;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(FileName".inp", "r")) {
freopen(FileName".inp", "r", stdin);
freopen(FileName".out", "w", stdout);
}
/* int nTest; cin >> nTest;
while(nTest --)*/ Enter(), Solve();
return 0;
}
Compilation message (stderr)
sculpture.cpp: In function 'int main()':
sculpture.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FileName".inp", "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FileName".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... |