#include "shortcut.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const ll INF = 1e18;
const int MN = 3000;
ll DP1[MN][MN], DP2[MN][MN], DP3[MN][MN], DP4[MN][MN];
static bool posib(int n, vll alpha, vll beta, vll s, ll l, ll c) {
vll gamma(n, 0);
for(int i = 0; i < n; ++i)
gamma[i] = l - alpha[i];
for(int i = 0; i < n; ++i)
DP1[0][i] = DP2[0][i] = DP3[0][i] = DP4[0][i] = -INF;
for(int d = 0; d < n; ++d) {
for(int i = 0; i < n; ++i) {
int j = i + d;
if(j >= n) break;
if(beta[j] > gamma[i]) {
DP1[j - i][i] = alpha[i] + alpha[j];
DP2[j - i][i] = beta[j] + alpha[i];
DP3[j - i][i] = beta[i] + alpha[j];
DP4[j - i][i] = beta[i] + beta[j];
} else
DP1[j - i][i] = DP2[j - i][i] = DP3[j - i][i] = DP4[j - i][i] = -INF;
}
}
for(int len = 1; len < n; ++len)
for(int i = 0; i < n; ++i) {
int j = i + len;
if(j >= n) break;
if(j) {
DP1[j - i][i] = max(DP1[len][i], DP1[len - 1][i]);
DP3[j - i][i] = max(DP3[len][i], DP3[len - 1][i]);
}
if(i + 1 < n && len) {
DP3[len][i] = max(DP3[len][i], DP3[len - 1][i + 1]);
DP4[len][i] = max(DP4[len][i], DP4[len - 1][i + 1]);
}
}
for(int len = n - 1; len >= 0; --len)
for(int i = 0; i < n; ++i) {
int j = i + len;
if(j >= n) break;
if(i && len + 1 < n) {
DP1[len][i] = max(DP1[len][i], DP1[len + 1][i - 1]);
DP2[len][i] = max(DP2[len][i], DP2[len + 1][i - 1]);
}
if(j + 1 < n && len + 1 < n) {
DP2[len][i] = max(DP2[len][i], DP2[len + 1][i]);
DP4[len][i] = max(DP4[len][i], DP4[len + 1][i]);
}
}
for(int d = 0; d < n; ++d) {
for(int a = 0; a < n; ++a) {
int b = d + a;
if(b >= n) break;
bool ok = true;
ok &= DP1[b - a][a] + s[a] + s[b] + c <= l;
ok &= DP2[b - a][a] + s[a] - s[b] + c <= l;
ok &= DP3[b - a][a] - s[a] + s[b] + c <= l;
ok &= DP4[b - a][a] - s[a] - s[b] + c <= l;
if(ok) return true;
}
}
return false;
}
ll find_shortcut(int n, vi l, vi d, int c) {
vll s(n, 0), alpha(n, 0), beta(n, 0);
for(int i = 1; i < n; ++i) {
s[i] = s[i - 1] + l[i - 1];
}
for(int i = 0; i < n; ++i) {
alpha[i] = d[i] - s[i];
beta[i] = d[i] + s[i];
}
ll st = 0, dr = (n + 2) * ll(1e9), mij;
while(st < dr) {
mij = (st + dr) / 2;
if(posib(n, alpha, beta, s, mij, c))
dr = mij;
else st = mij + 1;
}
return st;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
6592 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
6596 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
6592 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
6596 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
6592 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
6596 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
6592 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
6596 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
6592 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
6596 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
6592 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
6596 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
6592 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
6596 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
6592 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
6492 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
6492 KB |
n = 3, 4 is a correct answer |
5 |
Incorrect |
1 ms |
6596 KB |
n = 2, incorrect answer: jury 62 vs contestant 72 |
6 |
Halted |
0 ms |
0 KB |
- |