#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector <vector <pair <int, int>>> adj;
int N;
pair <int, ll> dijkstra(int s) {
priority_queue <pair <ll, int>> pq;
vector <ll> dis(N+1, 1e17);
vector <bool> processed(N+1);
dis[s] = 0;
pq.push({0, s});
int node = 0, mx = 0;
while (!pq.empty()) {
s = pq.top().second;
pq.pop();
if (processed[s])
continue;
processed[s] = true;
if (mx < dis[s]) {
mx = dis[s];
node = s;
}
for (auto i : adj[s]) {
if (dis[i.first] > dis[s] + i.second) {
dis[i.first] = dis[s] + i.second;
pq.push({-dis[i.first], i.first});
}
}
}
return {node, mx};
}
long long find_shortcut(int n, vector<int> l, vector<int> d, int c)
{
adj.resize(n * 2 + 5);
for (int i = 0; i+1 < n; i++) {
adj[i].push_back({i+1, l[i]});
adj[i+1].push_back({i, l[i]});
}
int ogn = n;
for (int i = 0; i < ogn; i++) {
if (d[i] == 0)
continue;
adj[i].push_back({n, d[i]});
adj[n].push_back({i, d[i]});
n++;
}
N = n;
pair <int, ll> res = dijkstra(0);
res = dijkstra(res.first);
ll ans = res.second;
for (int i = 0; i < ogn; i++) {
for (int j = i+1; j < ogn; j++) {
adj[i].push_back({j, c});
adj[j].push_back({i, c});
res = dijkstra(0);
res = dijkstra(res.first);
ans = min(ans, res.second);
adj[i].pop_back();
adj[j].pop_back();
}
}
return ans;
}
// int main() {
// int n;
// cin >> n;
// vector <int> l(n), d(n);
// for (int i = 0; i < n-1; i++)
// cin >> l[i];
// for (int i = 0; i < n; i++)
// cin >> d[i];
// int c;
// cin >> c;
// cout << find_shortcut(n, l, d, c) << '\n';
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
344 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
344 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
344 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
344 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
344 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
344 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
344 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
344 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
344 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
344 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
344 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
344 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
344 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
344 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Correct |
1 ms |
348 KB |
n = 9, 110 is a correct answer |
3 |
Correct |
0 ms |
348 KB |
n = 4, 21 is a correct answer |
4 |
Correct |
0 ms |
348 KB |
n = 3, 4 is a correct answer |
5 |
Correct |
0 ms |
344 KB |
n = 2, 62 is a correct answer |
6 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
7 |
Correct |
0 ms |
344 KB |
n = 3, 29 is a correct answer |
8 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
9 |
Correct |
0 ms |
348 KB |
n = 2, 3 is a correct answer |
10 |
Incorrect |
0 ms |
348 KB |
n = 2, incorrect answer: jury 2000000001 vs contestant -1294967296 |
11 |
Halted |
0 ms |
0 KB |
- |