#include <bits/stdc++.h>
#include "shortcut.h"
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define inf 1000000000000000000ll
using namespace std;
typedef long long ll;
ll find_shortcut(int n, vector<int> l_int, vector<int> d_int, int c_int){
vector<ll> l(n), d(n);
REP(i, n) l[i] = l_int[i], d[i] = d_int[i];
ll c = c_int;
vector<ll> pref(n, 0ll);
FOR(i, 1, n-1) pref[i] = pref[i-1]+l[i-1];
/*printf("pref: ");
for(ll x : pref) printf("%lld ", x);
printf("\n");*/
ll wyn = inf;
//int poc = 0, kon = 6;
REP(kon, n) REP(poc, kon){
ll odl = 0ll;
ll lewopoc = -inf;
ll lewokon = -inf;
FOR(i, 0, poc){
lewopoc = max(lewopoc, d[i]-pref[i]);
lewokon = max(lewokon, d[i]+pref[i]);
}
ll prawokon = -inf;
ll prawopoc = -inf;
FOR(i, kon, n-1){
prawokon= max(prawokon, d[i]+pref[i]);
prawopoc = max(prawopoc, d[i]-pref[i]);
}
odl = max(odl, lewopoc+prawokon-pref[kon]+pref[poc]+c);
odl = max(odl, lewopoc+lewokon);
odl = max(odl, prawopoc+prawokon);
//printf("odl: %lld\n", odl);
//printf("%lld %lld\n", lewo, prawo);
ll cykl = pref[kon]-pref[poc]+c;
FOR(i, poc, kon){
ll dopoc = pref[i]-pref[poc];
ll dokon = pref[kon]-pref[i];
dopoc = min(dopoc, cykl-dopoc);
dokon = min(dokon, cykl-dokon);
odl = max(odl, lewopoc+dopoc+pref[poc]+d[i]);
odl = max(odl, dokon+prawokon-pref[kon]+d[i]);
}
/*int it = poc;
FOR(i, poc, kon){
while(it < kon && pref[it+1]-pref[i] <= (cykl>>1)) ++it;
odl = max(odl, pref[it]-pref[i]+d[i]+d[it]);
}*/
FOR(i, poc, kon) FOR(j, i+1, kon){
ll t = pref[j]-pref[i];
t = min(t, cykl-t);
odl = max(odl, t+d[i]+d[j]);
}
//printf("%d %d: %lld\n", poc, kon, odl);
wyn = min(wyn, odl);
}
return wyn;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
600 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 4 vs contestant 5 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
600 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 4 vs contestant 5 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
600 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 4 vs contestant 5 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
600 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 4 vs contestant 5 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
600 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 4 vs contestant 5 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
600 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 4 vs contestant 5 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
600 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 4 vs contestant 5 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
0 ms |
600 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
1 ms |
344 KB |
n = 4, 21 is a correct answer |
4 |
Incorrect |
0 ms |
348 KB |
n = 3, incorrect answer: jury 4 vs contestant 5 |
5 |
Halted |
0 ms |
0 KB |
- |