#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
int n;
ll ans=LLONG_MAX;
vector<pii> adj[1005];
ll find_shortcut(int N, vector<int> l, vector<int> d, int c) {
n=N;
for (int i=0; i<n-1; ++i) {
adj[i].push_back(pii(i+1,l[i]));
adj[i+1].push_back(pii(i,l[i]));
}
vector<int> v;
for (int i=0; i<n; ++i) {
v.push_back(i);
if (d[i]) {
adj[i].push_back(pii(i+500,d[i]));
adj[i+500].push_back(pii(i,d[i]));
v.push_back(i+500);
}
}
for (int l=0; l<n; ++l) {
for (int r=l+1; r<n; ++r) {
int sum=0;
for (int i=l; i<r; ++i) sum+=d[i];
if (c>sum) continue;
//consider express in (l,r)
adj[l].push_back(pii(r,c));
adj[r].push_back(pii(l,c));
ll mmax=0;
for (auto st : v) {
priority_queue<pii, vector<pii>, greater<pii>> q;
ll dis[1005];
bool vis[1005];
for (int i=0; i<1003; ++i) dis[i]=1e18, vis[i]=false;
dis[st]=0;
q.push(pii(0,st));
while (!q.empty()) {
ll node=q.top().second;
q.pop();
mmax=max(mmax,dis[node]);
if (vis[node]) continue;
vis[node]=true;
for (auto s : adj[node]) {
if (dis[s.first]>dis[node]+s.second) {
dis[s.first]=dis[node]+s.second;
q.push(pii(dis[s.first],s.first));
}
}
}
}
ans=min(ans,mmax);
adj[l].pop_back();
adj[r].pop_back();
}
}
ll mmax=0;
for (auto st : v) {
priority_queue<pii, vector<pii>, greater<pii>> q;
ll dis[1005];
bool vis[1005];
for (int i=0; i<n+500; ++i) dis[i]=1e18, vis[i]=false;
dis[st]=0;
q.push(pii(0,st));
while (!q.empty()) {
ll node=q.top().second;
q.pop();
mmax=max(mmax,dis[node]);
if (vis[node]) continue;
vis[node]=true;
for (auto s : adj[node]) {
if (dis[s.first]>dis[node]+s.second) {
dis[s.first]=dis[node]+s.second;
q.push(pii(dis[s.first],s.first));
}
}
}
}
ans=min(ans,mmax);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 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 |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 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 |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 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 |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 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 |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 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 |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 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 |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 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 |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 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 |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 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 |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 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 |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 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 |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 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 |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 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 |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 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 |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 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 |
0 ms |
212 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 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 |
1 ms |
212 KB |
n = 3, 3000000000 is a correct answer |
14 |
Incorrect |
0 ms |
212 KB |
n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000 |
15 |
Halted |
0 ms |
0 KB |
- |