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>
using namespace std;
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
const ll N = 305;
const ll M = 1e9 + 7;
ll T, n, c[N], d[N], a, b;
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> a >> b;
vector <int> p(n+1,0);
for(int i = 1; i <= n; i++){
cin >> c[i];
p[i] = p[i-1] + c[i];
}
ll s = 0, ans = p[n];
for(int i = 1; i <= n; i++){
s += c[i];
vector <vector <ll>> dp(n+1, vector <ll> (n+1,1e9));
for(int j = i+1; j <= n; j++){
dp[j][1] = (p[j]-p[i])|s;
for(int j1 = j-1; j1 > i; j1--){
for(int ste = 1; ste < n; ste++){
dp[j][ste+1] = min(dp[j][ste+1],(dp[j1][ste]|(p[j]-p[j1]))|s);
}
}
}
for(int j = 1; j <= n; j++){
ans = min(ans,dp[n][j]);
}
}
cout << ans << "\n";
return 0;
}
// 6 1 3
// 8 1 2 1 5 4
# | 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... |