#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3000;
const ll INF = 1e18;
ll L[N],R[N],mxL[N],mxR[N],pre[N],dp[N][N];
vector<int> d,l;
bool vis[N][N];
int n;
ll c;
bool check(ll mid) {
for(int j=0;j<n;++j)
dp[j][j] = INF;
for (int len = 2; len <= n; ++len) {
for (int i = 0; i + len <= n; ++i) {
int j = i + len - 1;
if (pre[j] - pre[i] + d[i] + d[j] > mid)
dp[i][j] = (pre[j] - pre[i]) - d[i] - d[j];
else
dp[i][j] = INF;
if (dp[i][j] > dp[i + 1][j])
dp[i][j] = dp[i + 1][j];
if (dp[i][j] > dp[i][j - 1])
dp[i][j] = dp[i][j - 1];
}
}
bool ok = false;
for (int i = 0; i < n; ++i) {
if (mxL[i] > mid)
continue;
ll fage3 = -INF;
ll csum = 0;
for (int j = i + 1; j < n; ++j) {
csum += l[j - 1];
if (L[j] + d[j] > mid && fage3<L[i] + c + d[j])
fage3 = L[i] + c + d[j];
if (fage3 > mid || csum + c - dp[i][j] > mid)
break;
if (min(csum, c) + L[i] + R[j] <= mid && mxR[j] <= mid && csum + c - dp[i][j] <= mid) {
vis[i][j] = true;
ok = true;
}
else
vis[i][j] = false;
if (j != n - 1)
fage3 += l[j];
}
}
if (!ok)
return false;
for (int i = n - 1; i >= 0; --i) {
if (mxR[i] > mid)
continue;
ll fage3 = -INF;
for (int j = i - 1; j >= 0; j--) {
if (R[j] + d[j] > mid && fage3 < R[i] + c + d[j])
fage3 = R[i] + c + d[j];
if (fage3 > mid)
break;
if (mxL[j] <= mid && vis[j][i]) {
return true;
}
if (j != 0)
fage3 += l[j - 1];
}
}
return false;
}
ll find_shortcut(int n, vector<int> l, vector<int> d, int c){
if(n>3000)
return -1;
::n=n;
::d=d;
::c=c;
::l=l;
for (int i = 0; i < n; ++i){
L[i] = d[i];
if(i)
pre[i] = l[i-1] + pre[i-1];
if(i)
L[i] = max(L[i-1]+l[i-1],L[i]);
mxL[i] = max(i?mxL[i-1]:0,d[i]+ (i?L[i-1]+l[i-1]:0));
}
for(int i = n - 1 ; i >= 0 ; i--){
R[i] = d[i];
if(i != n-1)
R[i] = max(R[i],R[i+1]+l[i]);
mxR[i] = max(i!=n-1?mxR[i+1]:0,d[i] + (i!=n-1?R[i+1]+l[i]:0));
}
ll lo = 0 , hi = 1e9*(N+3),best = -1;
while(lo <= hi){
ll mid = (lo + hi)/2;
if(check(mid)){
best = mid;
hi = mid -1;
}else{
lo = mid + 1;
}
}
assert(best!=-1);
return best;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
81240 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
81240 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
81240 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
81240 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
81240 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
81240 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
81240 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
81240 KB |
n = 4, incorrect answer: jury 80 vs contestant 70 |
2 |
Halted |
0 ms |
0 KB |
- |