#include "shortcut.h"
#include <bits/stdc++.h>
#define endl '\n'
#define here cerr<<"=========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#define ll int
#define pb push_back
#define popb pop_back
#define all(a_) a_.begin(),a_.end()
#define pll pair<ll,ll>
#define sc second
#define fi first
#define llinf 1000000000
#define ceri(a,l,r) {for(ll i = l;i<=r;i++) cerr<<a[i]<< " ";cerr<<endl;}
using namespace std;
#define maxn 2000005
ll n,c,tsz;
vector<pll> g[maxn];
ll dis[maxn];
ll naj(ll x){
for(ll i = 0;i<=tsz;i++) dis[i] = llinf;
dis[x] = 0;
priority_queue<pll> pq;
pq.push({0,x});
while(pq.size()){
ll u = pq.top().sc;
ll cur = -pq.top().fi;
pq.pop();
if(cur!=dis[u]) continue;
for(pll p : g[u]){
ll s = p.fi;
ll w = p.sc;
if(cur+w<dis[s]){
dis[s] = cur+w;
pq.push({-dis[s],s});
}
}
}
ll ans = 1;
for(ll i = 1;i<=tsz;i++) if(dis[i]>dis[ans]) ans = i;
return ans;
}
long long find_shortcut(int N, vector<int> L, vector<int> D, int C)
{
n = N;
tsz = n;
c = C;
for(ll i = 1;i<n;i++){
g[i].pb({i+1,L[i-1]});
g[i+1].pb({i,L[i-1]});
}
for(ll i = 1;i<=n;i++) if(D[i-1]){
g[i].pb({++tsz,D[i-1]});
g[tsz].pb({i,D[i-1]});
}
ll ans = llinf;
for(ll i = 1;i<=n;i++){
for(ll j = i+1;j<=n;j++){
g[i].pb({j,c});
g[j].pb({i,c});
ll cur = 0;
for(ll k = 1;k<=tsz;k++){
ll f = naj(k);
cur = max(cur,dis[f]);
}
ans = min(ans,cur);
g[i].popb();
g[j].popb();
}
}
return (ll)ans;
}
/**
4 10
10 20 20
0 40 0 30
9 30
10 10 10 10 10 10 10 10
20 0 30 0 0 40 0 40 0
**/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47192 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
25 ms |
47180 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
23 ms |
47208 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
23 ms |
47276 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
23 ms |
47188 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
27 ms |
47180 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
47188 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
47232 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000000 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47192 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
25 ms |
47180 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
23 ms |
47208 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
23 ms |
47276 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
23 ms |
47188 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
27 ms |
47180 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
47188 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
47232 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000000 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47192 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
25 ms |
47180 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
23 ms |
47208 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
23 ms |
47276 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
23 ms |
47188 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
27 ms |
47180 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
47188 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
47232 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000000 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47192 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
25 ms |
47180 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
23 ms |
47208 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
23 ms |
47276 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
23 ms |
47188 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
27 ms |
47180 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
47188 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
47232 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000000 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47192 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
25 ms |
47180 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
23 ms |
47208 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
23 ms |
47276 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
23 ms |
47188 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
27 ms |
47180 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
47188 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
47232 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000000 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47192 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
25 ms |
47180 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
23 ms |
47208 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
23 ms |
47276 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
23 ms |
47188 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
27 ms |
47180 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
47188 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
47232 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000000 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47192 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
25 ms |
47180 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
23 ms |
47208 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
23 ms |
47276 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
23 ms |
47188 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
27 ms |
47180 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
47188 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
47232 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000000 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
47192 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
25 ms |
47180 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
23 ms |
47208 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
23 ms |
47276 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
23 ms |
47188 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
27 ms |
47180 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
23 ms |
47188 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
23 ms |
47188 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
24 ms |
47232 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant 1000000000 |
11 |
Halted |
0 ms |
0 KB |
- |