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;
typedef long long int64;
const int maxn = 1e2 + 2;
const int maxbit = 512;
bool dp[maxn][maxn][maxbit];
int pref [maxn];
int arr[maxn];
vector <int> v[maxbit][maxbit]; // v[x][y] -> all integer z that x | z = y
int main() {
int n,a,b;
cin >> n >> a >> b;
for (int i = 0; i < maxbit; i++){
for (int j = 0; j < maxbit; j++){
v[i][i | j].push_back(j);
}
}
for (int i = 1; i <= n; i++){
cin >> arr[i];
pref[i] = pref[i-1] + arr[i];
dp[i][1][pref[i]] = 1;
}
for (int k = 2; k <= b; k++){
for (int r = 1; r <= n; r++){
for (int l = 1; l <= r; l++){
for (int ans = 0; ans < maxbit; ans++){
for (int z: v[pref[r] - pref[l - 1]][ans]) dp[r][k][ans] |= dp[l-1][k-1][z];
// for (int to = 0; to <= ans; to++){
}
}
}
}
int rs = 1e9;
for (int i = a; i <= b; i++){
for (int j = 0; j < maxbit; j++)
rs = min(rs, dp[n][i][j] ? j: (int) 1e9);
}
cout << rs << "\n";
return 0;
}
# | 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... |