Submission #959158

# Submission time Handle Problem Language Result Execution time Memory
959158 2024-04-07T14:24:21 Z Ahmed57 Shortcut (IOI16_shortcut) C++17
0 / 100
2 ms 2652 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 = 0;i<n;i++){
        adj[i].clear();
    }
    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;
    int pr[2*n+1] = {0};
    for(int i = 0;i<n;i++){
        if(d[i]){
            pr[cnt] = i;
            adj[cnt].clear();
            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;
    if(f>=n)f = pr[f];
    if(s>=n)s = pr[n];
    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(4, {10,20,20},{0,40,0,30},10);
}*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2652 KB n = 9, 110 is a correct answer
3 Incorrect 2 ms 2652 KB n = 4, incorrect answer: jury 21 vs contestant 15
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2652 KB n = 9, 110 is a correct answer
3 Incorrect 2 ms 2652 KB n = 4, incorrect answer: jury 21 vs contestant 15
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2652 KB n = 9, 110 is a correct answer
3 Incorrect 2 ms 2652 KB n = 4, incorrect answer: jury 21 vs contestant 15
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2652 KB n = 9, 110 is a correct answer
3 Incorrect 2 ms 2652 KB n = 4, incorrect answer: jury 21 vs contestant 15
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2652 KB n = 9, 110 is a correct answer
3 Incorrect 2 ms 2652 KB n = 4, incorrect answer: jury 21 vs contestant 15
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2652 KB n = 9, 110 is a correct answer
3 Incorrect 2 ms 2652 KB n = 4, incorrect answer: jury 21 vs contestant 15
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2652 KB n = 9, 110 is a correct answer
3 Incorrect 2 ms 2652 KB n = 4, incorrect answer: jury 21 vs contestant 15
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2652 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2652 KB n = 9, 110 is a correct answer
3 Incorrect 2 ms 2652 KB n = 4, incorrect answer: jury 21 vs contestant 15
4 Halted 0 ms 0 KB -