#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll prefix[3005];
ll bestB[3005];
ll bestA[3005];
long long find_shortcut(int n, vector<int> l, vector<int> d, int c) {
vector<int> L = {0,0};
for(auto i: l) L.push_back(i);
l=L;
vector<ll> D = {0};
for(auto i: d) D.push_back(i);
d.clear();
for(auto i: D) d.push_back(i);
for(int i = 1; i <= n; i++)
prefix[i] = prefix[i-1] + l[i];
ll diam = 1ll<<50;
vector<ll> Db = D;
for(int i = 2; i <= n; i++)
Db[i] = max(Db[i], Db[i-1]+(ll)l[i]);
vector<ll> Da = D;
for(int i = n-1; i >= 1; i--)
Da[i] = max(Da[i], Da[i+1]+(ll)l[i+1]);
// cerr << " ";
// for(int i = 2; i <= n; i++)
// cerr << l[i] << " ";
// cerr << endl;
// for(int i = 1; i <= n; i++) {
// cerr << d[i] << " ";
// if(d[i]==0)
// cerr << " ";
// }
// cerr << endl;
// cerr << endl;
//
// for(int i = 1; i <= n; i++)
// cerr << Db[i] << " ";
// cerr << endl;
// cerr << endl;
// for(int i = 1; i <= n; i++)
// cerr << Da[i] << " ";
// cerr << endl;
// cerr << endl;
for(int i = 1; i <= n; i++)
for(int j = i+1; j <= n; j++)
bestB[j] = max(bestB[j], prefix[j]-prefix[i] + (ll)d[i] + (ll)d[j]),
bestA[i] = max(bestA[i], prefix[j]-prefix[i] + (ll)d[i] + (ll)d[j]);
// for(int i = 1; i <= n; i++)
// cerr << bestB[i] << " ";
// cerr << endl;
// for(int i = 1; i <= n; i++)
// cerr << bestA[i] << " ";
// cerr << endl;
// cerr << endl;
for(ll ci = 1; ci <= n; ci++) {
for(ll cj = ci+1; cj <= n; cj++) {
D[ci] = Db[ci];
D[cj] = Da[cj];
ll currDiam = max(bestB[ci], bestA[cj]);
for(ll i = 1; i <= cj; i++)
for(ll j = i+1; j <= cj; j++)
currDiam = max(currDiam, min(prefix[j]-prefix[i] + D[i] + D[j], prefix[cj]-prefix[j] + c + prefix[i]-prefix[ci] + D[i] + D[j]));
diam = min(diam, currDiam);
D[ci] = d[ci];
D[cj] = d[cj];
}
}
return diam;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
360 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
408 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
484 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
484 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
484 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
492 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
496 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
3 ms |
620 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
3 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
620 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
3 ms |
620 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
3 ms |
620 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
620 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
620 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
3 ms |
636 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
636 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
2 ms |
672 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
3 ms |
676 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
2 ms |
680 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
360 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
408 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
484 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
484 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
484 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
492 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
496 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
3 ms |
620 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
3 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
620 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
3 ms |
620 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
3 ms |
620 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
620 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
620 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
3 ms |
636 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
636 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
2 ms |
672 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
3 ms |
676 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
2 ms |
680 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
360 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
408 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
484 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
484 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
484 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
492 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
496 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
3 ms |
620 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
3 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
620 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
3 ms |
620 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
3 ms |
620 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
620 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
620 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
3 ms |
636 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
636 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
2 ms |
672 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
3 ms |
676 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
2 ms |
680 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
360 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
408 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
484 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
484 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
484 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
492 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
496 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
3 ms |
620 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
3 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
620 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
3 ms |
620 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
3 ms |
620 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
620 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
620 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
3 ms |
636 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
636 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
2 ms |
672 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
3 ms |
676 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
2 ms |
680 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
360 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
408 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
484 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
484 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
484 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
492 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
496 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
3 ms |
620 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
3 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
620 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
3 ms |
620 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
3 ms |
620 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
620 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
620 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
3 ms |
636 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
636 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
2 ms |
672 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
3 ms |
676 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
2 ms |
680 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
360 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
408 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
484 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
484 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
484 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
492 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
496 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
3 ms |
620 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
3 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
620 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
3 ms |
620 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
3 ms |
620 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
620 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
620 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
3 ms |
636 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
636 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
2 ms |
672 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
3 ms |
676 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
2 ms |
680 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
360 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
408 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
484 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
484 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
484 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
492 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
496 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
3 ms |
620 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
3 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
620 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
3 ms |
620 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
3 ms |
620 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
620 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
620 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
3 ms |
636 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
636 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
2 ms |
672 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
3 ms |
676 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
2 ms |
680 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
2 ms |
360 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
2 ms |
408 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
2 ms |
484 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
3 ms |
484 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
3 ms |
484 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
2 ms |
492 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
3 ms |
492 KB |
n = 2, 3 is a correct answer |
10 |
Correct |
2 ms |
496 KB |
n = 2, 2000000001 is a correct answer |
11 |
Correct |
3 ms |
620 KB |
n = 2, 3000000000 is a correct answer |
12 |
Correct |
3 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
13 |
Correct |
2 ms |
620 KB |
n = 3, 3000000000 is a correct answer |
14 |
Correct |
2 ms |
620 KB |
n = 4, 3000000001 is a correct answer |
15 |
Correct |
3 ms |
620 KB |
n = 4, 4000000000 is a correct answer |
16 |
Correct |
3 ms |
620 KB |
n = 5, 4000000000 is a correct answer |
17 |
Correct |
2 ms |
620 KB |
n = 10, 1000000343 is a correct answer |
18 |
Correct |
2 ms |
620 KB |
n = 10, 3189 is a correct answer |
19 |
Correct |
3 ms |
636 KB |
n = 10, 7000000000 is a correct answer |
20 |
Correct |
2 ms |
636 KB |
n = 5, 12 is a correct answer |
21 |
Correct |
2 ms |
672 KB |
n = 5, 25 is a correct answer |
22 |
Correct |
3 ms |
676 KB |
n = 2, 122 is a correct answer |
23 |
Incorrect |
2 ms |
680 KB |
n = 10, incorrect answer: jury 117 vs contestant 110 |
24 |
Halted |
0 ms |
0 KB |
- |