#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}
void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
_print(H);
if(sizeof...(T)) cerr<<",";
else cerr<<"\"]";
dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxn=101;
int n,a,b;
ll dp[mxn][mxn];
ll sum[mxn];
// dp[i][j] = minval from a[0,i] with j group
vector<int> ar;
ll f(int l,int r) {
if(!l) return sum[r];
return sum[r]-sum[l-1];
}
ll dfs(int pos,int cnt) {
if(pos<0) return 0;
if(cnt>b) return 1e16;
if(dp[pos][cnt]!=-1) return dp[pos][cnt];
ll res=1e16;
for(int i=pos-1;i>=0;i--) {
res=min(res,dfs(i,cnt-1)|f(i+1,pos));
}
return dp[pos][cnt]=res;
}
int main () {
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>a>>b;
ar.resize(n);
for(int i=0;i<n;i++) cin>>ar[i];
memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++) {
sum[i]=ar[i];
if(i) sum[i]+=sum[i-1];
dp[i][1]=sum[i];
}
dp[0][0]=0;
ll ans=1e16;
for(int i=a;i<=b;i++) {
ans=min(ans,dfs(n-1,i));
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
380 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |