Submission #572848

# Submission time Handle Problem Language Result Execution time Memory
572848 2022-06-05T11:36:10 Z jasmin Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 308 KB
#include<bits/stdc++.h>
#include "shortcut.h"

using namespace std;
const long long inf=1e18;

int farthest(int a, vector<vector<pair<int,int> > >& adi, int n){
    vector<long long> dist(n, inf);
    vector<bool> vis(n);
    dist[a]=0;
    priority_queue<pair<int,int> > pq;
    pq.push({-0, a});

    int ans=a;
    while(!pq.empty()){
        int v=pq.top().second;
        pq.pop();

        if(vis[v]) continue;
        vis[v]=true;
        ans=v;

        for(auto u: adi[v]){
            if(dist[v]+u.second<dist[u.first]){
                dist[u.first]=dist[v]+u.second;
                pq.push({-dist[u.first], u.first});
            }
        }
    }
    return dist[ans];
}

int diameter(int n, vector<vector<pair<int,int> > >& adi){
    int ans=0;
    for(int i=0; i<n; i++){
        ans=max(ans, farthest(i, adi, n));
    }
    return ans;
}

long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
    vector<vector<pair<int,int> > > adi(n*2);
    for(int i=0; i<n-1; i++){
        adi[i].push_back({i+1, l[i]});
        adi[i+1].push_back({i, l[i]});
    }
    for(int i=0; i<n; i++){
        adi[i].push_back({i+n, d[i]});
        adi[i+n].push_back({i, d[i]});
    }

    int best=diameter(n*2, adi);
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){

            adi[i].push_back({j, c});
            adi[j].push_back({i, c});
            /*if(diameter(n*2, adi)<best){
                cout << "=> " << diameter(n*2, adi) << " " << i << " " << j << "\n";
            }*/
            best=min(best, diameter(n*2, adi));
            adi[i].pop_back();
            adi[j].pop_back();

        }
    }
    return best;
}

/*signed main(){
    int n;
    cin >> n;
    vector<int> l(n-1);
    for(int i=0; i<n-1; i++){
        cin >> l[i];
    }
    vector<int> d(n);
    for(int i=0; i<n; i++){
        cin >> d[i];
    }
    int c;
    cin >> c; 

    cout << find_shortcut(n, l, d, c) << "\n";
}*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 308 KB n = 9, 110 is a correct answer
3 Correct 0 ms 304 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 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 1 ms 304 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 2000000001 vs contestant 2000000000
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 308 KB n = 9, 110 is a correct answer
3 Correct 0 ms 304 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 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 1 ms 304 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 2000000001 vs contestant 2000000000
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 308 KB n = 9, 110 is a correct answer
3 Correct 0 ms 304 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 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 1 ms 304 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 2000000001 vs contestant 2000000000
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 308 KB n = 9, 110 is a correct answer
3 Correct 0 ms 304 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 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 1 ms 304 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 2000000001 vs contestant 2000000000
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 308 KB n = 9, 110 is a correct answer
3 Correct 0 ms 304 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 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 1 ms 304 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 2000000001 vs contestant 2000000000
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 308 KB n = 9, 110 is a correct answer
3 Correct 0 ms 304 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 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 1 ms 304 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 2000000001 vs contestant 2000000000
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 308 KB n = 9, 110 is a correct answer
3 Correct 0 ms 304 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 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 1 ms 304 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 2000000001 vs contestant 2000000000
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 1 ms 308 KB n = 9, 110 is a correct answer
3 Correct 0 ms 304 KB n = 4, 21 is a correct answer
4 Correct 1 ms 212 KB n = 3, 4 is a correct answer
5 Correct 1 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 1 ms 304 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Incorrect 0 ms 212 KB n = 2, incorrect answer: jury 2000000001 vs contestant 2000000000
11 Halted 0 ms 0 KB -