#include <bits/stdc++.h>
using namespace std;
#include "shortcut.h"
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define ll long long
const ll INF = 2e18 + 7;
long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
vector<ll> pre(n + 5, 0), suf(n + 5, 0), dist(n + 5, 0);
ll maks[n + 5][n + 5], maks2[n + 5][n + 5];
for (int i = 0; i < n + 5; i++){
for (int j = 0; j < n + 5; j++)
maks[i][j] = 0, maks2[i][j] = 0;
}
pre[0] = d[0];
for (int i = 1; i < n; i++){
pre[i] = pre[i - 1] + l[i - 1];
pre[i] = max(pre[i], (ll)d[i]);
}
suf[n - 1] = d[n - 1];
for (int i = n - 2; i >= 0; i--){
suf[i] = suf[i + 1] + l[i];
suf[i] = max(suf[i], (ll)d[i]);
}
for (int i = 1; i < n; i++)
dist[i] = dist[i - 1] + l[i - 1];
for (int i = 0; i < n; i++){
maks[i][i] = d[i];
for (int j = i -1; j >= 0; j--){
maks[j][i] = max(maks[j + 1][i], dist[i] - dist[j] + d[j]);
}
}
for (int i = 0; i < n; i++){
maks2[i][i] = d[i];
for (int j = i + 1; j < n; j++){
maks2[i][j] = max(maks2[i][j - 1], dist[j] - dist[i] + d[j] + d[i]);
}
}
ll ans = 0;
for (int i = 0; i < n; i++){
ans = max(ans, (ll)d[i]);
for (int j = i + 1; j < n; j++){
ans = max(ans, dist[j] - dist[i] + d[i] + d[j]);
}
}
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
ll pos = i, curr = pre[i] + suf[j] + c;
for (int k = i; k <= j; k++){
//cout<<i<<sp<<j<<sp<<curr<<endl;
if (k != j) curr = max(curr, suf[j] + d[k] + min(dist[k] - dist[i] + c, dist[j] - dist[k]));
else if (j < n - 1) curr = max(curr, suf[j + 1] + l[j] + d[k] + min(dist[k] - dist[i] + c, dist[j] - dist[k]));
if (k != i) curr = max(curr, pre[i] + d[k] + min(dist[k] - dist[i], dist[j] - dist[k] + c));
else if (i > 0) curr = max(curr, pre[i - 1] + l[i - 1] + d[k] + min(dist[k] - dist[i], dist[j] - dist[k] + c));
while(pos <= j && dist[pos] - dist[k] < dist[j] - dist[pos] + dist[k] - dist[i] + c){
pos++;
}
if (pos <= j) curr = max(curr, d[k] + dist[k] - dist[i] + c + maks[pos][j]);
if (pos > k) curr = max(curr, maks2[k][pos - 1]);
curr = max(curr, (ll)d[k]);
}
//cout<<i<<sp<<j<<sp<<curr<<endl;
ans = min(ans, curr);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 117 vs contestant 111 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 117 vs contestant 111 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 117 vs contestant 111 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 117 vs contestant 111 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 117 vs contestant 111 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 117 vs contestant 111 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 117 vs contestant 111 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
212 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
212 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
1 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
1 ms |
212 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
212 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
212 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
0 ms |
212 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
0 ms |
212 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
0 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
0 ms |
212 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
0 ms |
212 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
0 ms |
212 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
1 ms |
212 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
0 ms |
212 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
0 ms |
212 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
0 ms |
212 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
0 ms |
212 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
0 ms |
212 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
0 ms |
212 KB |
n = 10, incorrect answer: jury 117 vs contestant 111 |
24 |
Halted |
0 ms |
0 KB |
- |