Submission #605006

#TimeUsernameProblemLanguageResultExecution timeMemory
605006MohamedFaresNebiliShortcut (IOI16_shortcut)C++14
23 / 100
2076 ms340 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...