Submission #959128

# Submission time Handle Problem Language Result Execution time Memory
959128 2024-04-07T14:03:57 Z Ahmed57 Shortcut (IOI16_shortcut) C++17
0 / 100
2 ms 2648 KB
#include "bits/stdc++.h"
#include "shortcut.h"

using namespace std;
vector<pair<int,int>> adj[100001];
int ma = -1 , lol = -1;
void dfs(int i,int pr,int dep){
    if(ma<dep){
        ma = dep;
        lol = i;
    }
    for(auto j:adj[i]){
        if(j.first==pr)continue;
        dfs(j.first,i,dep+j.second);
    }
}
int cnt = 0;
long long oo = 1e18;
long long shortcut(int a,int b,int c){
    vector<pair<long long,long long>> ne[cnt];
    for(int i = 0;i<cnt;i++){
        for(auto j:adj[i]){
            ne[i].push_back(j);
        }
        if(i==a){
            ne[i].push_back({b,c});
        }if(i==b){
            ne[i].push_back({a,c});
        }
    }
    long long fin = 0;
    for(int i = 0;i<cnt;i++){
        long long dist[cnt];
        for(int j = 0;j<cnt;j++)dist[j] = oo;
        dist[i] = 0;
        priority_queue<pair<long long,long long>> q;
        q.push({0,i});
        while(!q.empty()){
            long long x = q.top().second , co = -q.top().first;
            q.pop();
            if(dist[x]<co)continue;
            for(auto j:ne[x]){
                if(dist[j.first]>co+j.second){
                    dist[j.first] = co+j.second;
                    q.push({-dist[j.first],j.first});
                }
            } 
        }
        for(int j = 0;j<cnt;j++){
            fin = max(fin,dist[j]);
        }
    }
    return fin;
}
long long find_shortcut(int n, vector<int> l, vector<int> d, int c){
    for(int i = 1;i<n;i++){
        adj[i-1].push_back({i,l[i-1]});
        adj[i].push_back({i-1,l[i-1]});
    }
    cnt = n;
    for(int i = 0;i<n;i++){
        if(d[i]){
            adj[i].push_back({cnt,d[i]});
            adj[cnt].push_back({i,d[i]});
            cnt++;
        }
    }
    dfs(0,-1,0);
    ma = -1;
    int f = lol;
    dfs(lol,-1,0);
    int s = lol;
    long long mi = oo;
    for(int i = 0;i<cnt;i++){
        mi = min(shortcut(i,f,c),mi);
        mi = min(shortcut(i,s,c),mi);
    }
    return mi;
}
/*
int main(){
    cout<<find_shortcut(9, {10, 10, 10, 10, 10, 10, 10, 10},{20, 0, 30, 0, 0, 40, 0, 40, 0}, 30);
}*/
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2648 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2648 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2648 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2648 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2648 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2648 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2648 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2648 KB n = 4, incorrect answer: jury 80 vs contestant 60
2 Halted 0 ms 0 KB -