# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1057056 |
2024-08-13T13:45:45 Z |
fv3 |
Shortcut (IOI16_shortcut) |
C++14 |
|
0 ms |
348 KB |
#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<pair<int, ll>>> adj;
int N;
vector<int> visited;
vector<ll> dist;
ll find_diameter()
{
visited = vector<int>(N);
dist = vector<ll>(N, 1ll << 60);
priority_queue<pair<ll, int>> q;
q.push({0, 0});
dist[0] = 0;
int mx_index;
while (1)
{
int s = q.top().second;
q.pop();
if (visited[s]) continue;
visited[s] = 1;
for (auto node : adj[s])
{
if (visited[node.first] || dist[s] + node.second > dist[node.first]) continue;
dist[node.first] = dist[s] + node.second;
q.push({-dist[node.first], node.first});
}
if (q.empty())
{
mx_index = s;
break;
}
}
visited = vector<int>(N);
dist = vector<ll>(N, 1ll << 60);
q.push({0, mx_index});
dist[mx_index] = 0;
int cnt = 0;
while (1)
{
int s = q.top().second;
q.pop();
if (visited[s]) continue;
visited[s] = 1; cnt++;
for (auto node : adj[s])
{
if (visited[node.first] || dist[s] + node.second > dist[node.first]) continue;
dist[node.first] = dist[s] + node.second;
q.push({-dist[node.first], node.first});
}
if (cnt == N)
{
return dist[s];
}
}
return 0;
}
ll find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
N = 2 * n;
adj.resize(N);
for (int i = 0; i < n - 1; i++)
{
adj[i].push_back({i+1, l[i]});
adj[i+1].push_back({i, l[i]});
}
for (int i = 0; i < n; i++)
{
adj[i].push_back({i+n, d[i]});
adj[i+n].push_back({i, d[i]});
}
ll res = 1ll << 60;
for (int i = 0; i < n - 1; i++)
{
for (int j = i+1; j < n; j++)
{
adj[i].push_back({j, c});
adj[j].push_back({i, c});
res = min(res, find_diameter());
adj[i].pop_back();
adj[j].pop_back();
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
n = 4, 80 is a correct answer |
2 |
Incorrect |
0 ms |
348 KB |
n = 9, incorrect answer: jury 110 vs contestant 100 |
3 |
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 |
Incorrect |
0 ms |
348 KB |
n = 9, incorrect answer: jury 110 vs contestant 100 |
3 |
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 |
Incorrect |
0 ms |
348 KB |
n = 9, incorrect answer: jury 110 vs contestant 100 |
3 |
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 |
Incorrect |
0 ms |
348 KB |
n = 9, incorrect answer: jury 110 vs contestant 100 |
3 |
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 |
Incorrect |
0 ms |
348 KB |
n = 9, incorrect answer: jury 110 vs contestant 100 |
3 |
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 |
Incorrect |
0 ms |
348 KB |
n = 9, incorrect answer: jury 110 vs contestant 100 |
3 |
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 |
Incorrect |
0 ms |
348 KB |
n = 9, incorrect answer: jury 110 vs contestant 100 |
3 |
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 |
Incorrect |
0 ms |
348 KB |
n = 9, incorrect answer: jury 110 vs contestant 100 |
3 |
Halted |
0 ms |
0 KB |
- |