#include <bits/stdc++.h>
#define pb push_back
#define task "sequence"
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define fi first
#define se second
using ll = long long;
const long long mod = 1e12+7;
const ll N = 2005;
const int base = 350;
using ull = unsigned long long;
using namespace std;
ll n, m, t, k, T, a[N], cnt, lab[N], l, r, ans, u, tong, v, b[N][N];
long long dp[2][N], c[N];
string s, ss;
vector<ll> kq;
vector<ll> adj[N];
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = (total * k) % mod;
k = (k * k) % mod;
}
return total;
}
void cal(ll l, ll r, ll opl, ll opr, ll pos)
{
if(l > r)return;
ll mid = (l + r) / 2;
ll best = mid;
dp[1][mid] = -mod;
for(int i = max(opl, pos); i <= min(opr, mid); i ++)
{
if(dp[1][mid] < dp[0][i] + (c[mid] - c[i]) * c[i])
{
dp[1][mid] = dp[0][i] + (c[mid] - c[i]) * c[i];
best = i;
}
}
b[pos][mid] = best;
cal(l, mid-1, opl, best, pos);
cal(mid+1, r, best, opr, pos);
}
void sol()
{
cin >> n >> l >> r;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
c[i] = c[i-1] + a[i];
b[i][0] = mod;
}
ans = mod;
for(int i = 1; i <= r; i ++)
{
for(int j = i; j <= n; j ++)
{
b[j][i] = mod;
for(int l = i; l <= j; l ++)
{
b[j][i] = min(b[j][i], (b[l-1][i-1] | (c[j] - c[l-1])));
}
//cout << j <<" "<<i<<" "<<b[j][i] << '\n';
}
if(i >= l)ans = min(ans, b[n][i]);
}
cout << ans;
}
int main()
{
if(fopen(task".in", "r")){
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest;
ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
/*
6 1 3
8 1 2 1 5 4
*/
Compilation message
sculpture.cpp: In function 'int main()':
sculpture.cpp:77:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
77 | freopen(task".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:78:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
78 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |