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 ll;
const int maxn = 2000 + 10;
const ll inf = 1e18;
bool g[maxn][maxn], cp[maxn][maxn];
ll a[maxn], dp[110][110];
int pd[maxn];
int shortest_path(int n, int A, int B){
if (A == 1){
for (int i = 1; i <= n; i++)
pd[i] = n + 1;
pd[0] = 0;
for (int i = 1; i <= n; i++)
for (int j = 0; j < i; j++)
if (g[j][i])
pd[i] = min(pd[i], pd[j] + 1);
return pd[n] <= B;
}
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= B; j++)
for (int k = i - 1; k >= 0; k--)
dp[i][j] |= dp[k][j - 1];
int ret = 0;
for (int i = A; i <= B; i++)
ret |= dp[n][i];
return ret;
}
int main(){
ios_base::sync_with_stdio(false);
int n, A, B;
cin >> n >> A >> B;
for (int i = 1; i <= n; i++){
cin >> a[i];
a[i] += a[i - 1];
}
for (int i = 0; i <= n; i++)
for (int j = i + 1; j <= n; j++)
g[i][j] = 1;
ll untilnow = 0;
for (int i = 60; i >= 0; i--){
for (int j = 0; j <= n; j++)
for (int k = 0; k <= n; k++)
cp[j][k] = g[j][k];
for (int j = 0; j <= n; j++)
for (int k = j + 1; k <= n; k++)
if ((a[k] - a[j]) & (1ll << i))
g[j][k] = 0;
if (!shortest_path(n, A, B)){
untilnow += (1ll << i);
for (int j = 0; j <= n; j++)
for (int k = 0; k <= n; k++)
g[j][k] = cp[j][k];
}
}
cout << untilnow << endl;
}
# | 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... |