This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<ll, ll>;
using vi = vector<int>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb lower_bound
ll solve(int N, vector<int> e, vector<int> d, int c, int S, int i, int j, vector<ll>& D) {
priority_queue<pair<ll, int>,
vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
pq.push({0, S}); D.assign(N, 1000000000000000007); D[S] = 0;
while(!pq.empty()) {
ll A = pq.top().ss, W = pq.top().ff; pq.pop();
if(W > D[A]) continue;
int V = A + 1;
if(A < N - 1 && D[V] > D[A] + e[A]) {
D[V] = D[A] + e[A];
pq.push({D[V], V});
}
V = A - 1;
if(A > 0 && D[V] > D[A] + e[A - 1]) {
D[V] = D[A] + e[A - 1];
pq.push({D[V], V});
}
if(A == i && D[A] + c < D[j]) {
D[j] = D[A] + c;
pq.push({D[j], j});
}
if(A == j && D[A] + c < D[i]) {
D[i] = D[A] + c;
pq.push({D[i], i});
}
}
ll best = 0;
for(int l = 0; l < N; l++) {
ll cur = D[l] + d[l];
if(l != S) cur += d[S];
best = max(best, cur);
}
return best;
}
long long find_shortcut(int N, vector<int> e, vector<int> d, int c) {
ll best = 1000000000000000007;
for(int i = 0; i < N; i++) {
for(int j = i + 1; j < N; j++) {
ll ans = 0;
for(int k = 0; k < N; k++) {
vector<ll> D;
ans = max(ans, solve(N, e, d, c, k, i, j, D));
}
best = min(best, ans);
}
}
return best;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |