답안 #959165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959165 2024-04-07T14:29:48 Z Ahmed57 Shortcut (IOI16_shortcut) C++17
0 / 100
2000 ms 2904 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;
    vector<int> lol;
    if(f>=n)f = pr[f];
    if(s>=n)s = pr[s];
    for(int i = max(0,f-3);i<min(n,f+4);i++)lol.push_back(i);
    for(int i = max(0,s-3);i<min(n,s+4);i++)lol.push_back(i);
    long long mi = oo;
    for(int i = 0;i<n;i++){
        for(auto j:lol){
            mi = min(shortcut(i,j,c),mi);
            mi = min(shortcut(i,j,c),mi);
        }
    }
    return mi;
}
/*
int main(){
    cout<<find_shortcut(4, {10,20,20},{0,40,0,30},10);
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2904 KB n = 9, 110 is a correct answer
3 Correct 1 ms 2652 KB n = 4, 21 is a correct answer
4 Correct 2 ms 2696 KB n = 3, 4 is a correct answer
5 Correct 1 ms 2904 KB n = 2, 62 is a correct answer
6 Correct 2 ms 2652 KB n = 2, 3 is a correct answer
7 Correct 1 ms 2652 KB n = 3, 29 is a correct answer
8 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
9 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
10 Correct 1 ms 2652 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 2652 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 2652 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 2652 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 2652 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 2652 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 2648 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 2652 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 2648 KB n = 10, 3189 is a correct answer
19 Correct 4 ms 2648 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 2652 KB n = 5, 12 is a correct answer
21 Correct 1 ms 2652 KB n = 5, 25 is a correct answer
22 Correct 1 ms 2648 KB n = 2, 122 is a correct answer
23 Correct 4 ms 2648 KB n = 10, 117 is a correct answer
24 Correct 3 ms 2648 KB n = 10, 336 is a correct answer
25 Correct 2 ms 2788 KB n = 10, 438 is a correct answer
26 Correct 1 ms 2652 KB n = 10, 206 is a correct answer
27 Correct 2 ms 2652 KB n = 10, 636 is a correct answer
28 Correct 1 ms 2652 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 2788 KB n = 10, 10992 is a correct answer
30 Correct 3 ms 2788 KB n = 10, 3112 is a correct answer
31 Correct 1540 ms 2784 KB n = 100, 51000000001 is a correct answer
32 Correct 648 ms 2800 KB n = 50, 197881272 is a correct answer
33 Execution timed out 2037 ms 2652 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2904 KB n = 9, 110 is a correct answer
3 Correct 1 ms 2652 KB n = 4, 21 is a correct answer
4 Correct 2 ms 2696 KB n = 3, 4 is a correct answer
5 Correct 1 ms 2904 KB n = 2, 62 is a correct answer
6 Correct 2 ms 2652 KB n = 2, 3 is a correct answer
7 Correct 1 ms 2652 KB n = 3, 29 is a correct answer
8 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
9 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
10 Correct 1 ms 2652 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 2652 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 2652 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 2652 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 2652 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 2652 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 2648 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 2652 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 2648 KB n = 10, 3189 is a correct answer
19 Correct 4 ms 2648 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 2652 KB n = 5, 12 is a correct answer
21 Correct 1 ms 2652 KB n = 5, 25 is a correct answer
22 Correct 1 ms 2648 KB n = 2, 122 is a correct answer
23 Correct 4 ms 2648 KB n = 10, 117 is a correct answer
24 Correct 3 ms 2648 KB n = 10, 336 is a correct answer
25 Correct 2 ms 2788 KB n = 10, 438 is a correct answer
26 Correct 1 ms 2652 KB n = 10, 206 is a correct answer
27 Correct 2 ms 2652 KB n = 10, 636 is a correct answer
28 Correct 1 ms 2652 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 2788 KB n = 10, 10992 is a correct answer
30 Correct 3 ms 2788 KB n = 10, 3112 is a correct answer
31 Correct 1540 ms 2784 KB n = 100, 51000000001 is a correct answer
32 Correct 648 ms 2800 KB n = 50, 197881272 is a correct answer
33 Execution timed out 2037 ms 2652 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2904 KB n = 9, 110 is a correct answer
3 Correct 1 ms 2652 KB n = 4, 21 is a correct answer
4 Correct 2 ms 2696 KB n = 3, 4 is a correct answer
5 Correct 1 ms 2904 KB n = 2, 62 is a correct answer
6 Correct 2 ms 2652 KB n = 2, 3 is a correct answer
7 Correct 1 ms 2652 KB n = 3, 29 is a correct answer
8 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
9 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
10 Correct 1 ms 2652 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 2652 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 2652 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 2652 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 2652 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 2652 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 2648 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 2652 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 2648 KB n = 10, 3189 is a correct answer
19 Correct 4 ms 2648 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 2652 KB n = 5, 12 is a correct answer
21 Correct 1 ms 2652 KB n = 5, 25 is a correct answer
22 Correct 1 ms 2648 KB n = 2, 122 is a correct answer
23 Correct 4 ms 2648 KB n = 10, 117 is a correct answer
24 Correct 3 ms 2648 KB n = 10, 336 is a correct answer
25 Correct 2 ms 2788 KB n = 10, 438 is a correct answer
26 Correct 1 ms 2652 KB n = 10, 206 is a correct answer
27 Correct 2 ms 2652 KB n = 10, 636 is a correct answer
28 Correct 1 ms 2652 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 2788 KB n = 10, 10992 is a correct answer
30 Correct 3 ms 2788 KB n = 10, 3112 is a correct answer
31 Correct 1540 ms 2784 KB n = 100, 51000000001 is a correct answer
32 Correct 648 ms 2800 KB n = 50, 197881272 is a correct answer
33 Execution timed out 2037 ms 2652 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2904 KB n = 9, 110 is a correct answer
3 Correct 1 ms 2652 KB n = 4, 21 is a correct answer
4 Correct 2 ms 2696 KB n = 3, 4 is a correct answer
5 Correct 1 ms 2904 KB n = 2, 62 is a correct answer
6 Correct 2 ms 2652 KB n = 2, 3 is a correct answer
7 Correct 1 ms 2652 KB n = 3, 29 is a correct answer
8 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
9 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
10 Correct 1 ms 2652 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 2652 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 2652 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 2652 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 2652 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 2652 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 2648 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 2652 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 2648 KB n = 10, 3189 is a correct answer
19 Correct 4 ms 2648 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 2652 KB n = 5, 12 is a correct answer
21 Correct 1 ms 2652 KB n = 5, 25 is a correct answer
22 Correct 1 ms 2648 KB n = 2, 122 is a correct answer
23 Correct 4 ms 2648 KB n = 10, 117 is a correct answer
24 Correct 3 ms 2648 KB n = 10, 336 is a correct answer
25 Correct 2 ms 2788 KB n = 10, 438 is a correct answer
26 Correct 1 ms 2652 KB n = 10, 206 is a correct answer
27 Correct 2 ms 2652 KB n = 10, 636 is a correct answer
28 Correct 1 ms 2652 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 2788 KB n = 10, 10992 is a correct answer
30 Correct 3 ms 2788 KB n = 10, 3112 is a correct answer
31 Correct 1540 ms 2784 KB n = 100, 51000000001 is a correct answer
32 Correct 648 ms 2800 KB n = 50, 197881272 is a correct answer
33 Execution timed out 2037 ms 2652 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2904 KB n = 9, 110 is a correct answer
3 Correct 1 ms 2652 KB n = 4, 21 is a correct answer
4 Correct 2 ms 2696 KB n = 3, 4 is a correct answer
5 Correct 1 ms 2904 KB n = 2, 62 is a correct answer
6 Correct 2 ms 2652 KB n = 2, 3 is a correct answer
7 Correct 1 ms 2652 KB n = 3, 29 is a correct answer
8 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
9 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
10 Correct 1 ms 2652 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 2652 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 2652 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 2652 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 2652 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 2652 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 2648 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 2652 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 2648 KB n = 10, 3189 is a correct answer
19 Correct 4 ms 2648 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 2652 KB n = 5, 12 is a correct answer
21 Correct 1 ms 2652 KB n = 5, 25 is a correct answer
22 Correct 1 ms 2648 KB n = 2, 122 is a correct answer
23 Correct 4 ms 2648 KB n = 10, 117 is a correct answer
24 Correct 3 ms 2648 KB n = 10, 336 is a correct answer
25 Correct 2 ms 2788 KB n = 10, 438 is a correct answer
26 Correct 1 ms 2652 KB n = 10, 206 is a correct answer
27 Correct 2 ms 2652 KB n = 10, 636 is a correct answer
28 Correct 1 ms 2652 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 2788 KB n = 10, 10992 is a correct answer
30 Correct 3 ms 2788 KB n = 10, 3112 is a correct answer
31 Correct 1540 ms 2784 KB n = 100, 51000000001 is a correct answer
32 Correct 648 ms 2800 KB n = 50, 197881272 is a correct answer
33 Execution timed out 2037 ms 2652 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2904 KB n = 9, 110 is a correct answer
3 Correct 1 ms 2652 KB n = 4, 21 is a correct answer
4 Correct 2 ms 2696 KB n = 3, 4 is a correct answer
5 Correct 1 ms 2904 KB n = 2, 62 is a correct answer
6 Correct 2 ms 2652 KB n = 2, 3 is a correct answer
7 Correct 1 ms 2652 KB n = 3, 29 is a correct answer
8 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
9 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
10 Correct 1 ms 2652 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 2652 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 2652 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 2652 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 2652 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 2652 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 2648 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 2652 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 2648 KB n = 10, 3189 is a correct answer
19 Correct 4 ms 2648 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 2652 KB n = 5, 12 is a correct answer
21 Correct 1 ms 2652 KB n = 5, 25 is a correct answer
22 Correct 1 ms 2648 KB n = 2, 122 is a correct answer
23 Correct 4 ms 2648 KB n = 10, 117 is a correct answer
24 Correct 3 ms 2648 KB n = 10, 336 is a correct answer
25 Correct 2 ms 2788 KB n = 10, 438 is a correct answer
26 Correct 1 ms 2652 KB n = 10, 206 is a correct answer
27 Correct 2 ms 2652 KB n = 10, 636 is a correct answer
28 Correct 1 ms 2652 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 2788 KB n = 10, 10992 is a correct answer
30 Correct 3 ms 2788 KB n = 10, 3112 is a correct answer
31 Correct 1540 ms 2784 KB n = 100, 51000000001 is a correct answer
32 Correct 648 ms 2800 KB n = 50, 197881272 is a correct answer
33 Execution timed out 2037 ms 2652 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2904 KB n = 9, 110 is a correct answer
3 Correct 1 ms 2652 KB n = 4, 21 is a correct answer
4 Correct 2 ms 2696 KB n = 3, 4 is a correct answer
5 Correct 1 ms 2904 KB n = 2, 62 is a correct answer
6 Correct 2 ms 2652 KB n = 2, 3 is a correct answer
7 Correct 1 ms 2652 KB n = 3, 29 is a correct answer
8 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
9 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
10 Correct 1 ms 2652 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 2652 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 2652 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 2652 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 2652 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 2652 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 2648 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 2652 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 2648 KB n = 10, 3189 is a correct answer
19 Correct 4 ms 2648 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 2652 KB n = 5, 12 is a correct answer
21 Correct 1 ms 2652 KB n = 5, 25 is a correct answer
22 Correct 1 ms 2648 KB n = 2, 122 is a correct answer
23 Correct 4 ms 2648 KB n = 10, 117 is a correct answer
24 Correct 3 ms 2648 KB n = 10, 336 is a correct answer
25 Correct 2 ms 2788 KB n = 10, 438 is a correct answer
26 Correct 1 ms 2652 KB n = 10, 206 is a correct answer
27 Correct 2 ms 2652 KB n = 10, 636 is a correct answer
28 Correct 1 ms 2652 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 2788 KB n = 10, 10992 is a correct answer
30 Correct 3 ms 2788 KB n = 10, 3112 is a correct answer
31 Correct 1540 ms 2784 KB n = 100, 51000000001 is a correct answer
32 Correct 648 ms 2800 KB n = 50, 197881272 is a correct answer
33 Execution timed out 2037 ms 2652 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2648 KB n = 4, 80 is a correct answer
2 Correct 2 ms 2904 KB n = 9, 110 is a correct answer
3 Correct 1 ms 2652 KB n = 4, 21 is a correct answer
4 Correct 2 ms 2696 KB n = 3, 4 is a correct answer
5 Correct 1 ms 2904 KB n = 2, 62 is a correct answer
6 Correct 2 ms 2652 KB n = 2, 3 is a correct answer
7 Correct 1 ms 2652 KB n = 3, 29 is a correct answer
8 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
9 Correct 1 ms 2652 KB n = 2, 3 is a correct answer
10 Correct 1 ms 2652 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 2652 KB n = 2, 3000000000 is a correct answer
12 Correct 2 ms 2652 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 2652 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 2652 KB n = 4, 3000000001 is a correct answer
15 Correct 1 ms 2652 KB n = 4, 4000000000 is a correct answer
16 Correct 1 ms 2648 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 2652 KB n = 10, 1000000343 is a correct answer
18 Correct 3 ms 2648 KB n = 10, 3189 is a correct answer
19 Correct 4 ms 2648 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 2652 KB n = 5, 12 is a correct answer
21 Correct 1 ms 2652 KB n = 5, 25 is a correct answer
22 Correct 1 ms 2648 KB n = 2, 122 is a correct answer
23 Correct 4 ms 2648 KB n = 10, 117 is a correct answer
24 Correct 3 ms 2648 KB n = 10, 336 is a correct answer
25 Correct 2 ms 2788 KB n = 10, 438 is a correct answer
26 Correct 1 ms 2652 KB n = 10, 206 is a correct answer
27 Correct 2 ms 2652 KB n = 10, 636 is a correct answer
28 Correct 1 ms 2652 KB n = 4, 2399 is a correct answer
29 Correct 3 ms 2788 KB n = 10, 10992 is a correct answer
30 Correct 3 ms 2788 KB n = 10, 3112 is a correct answer
31 Correct 1540 ms 2784 KB n = 100, 51000000001 is a correct answer
32 Correct 648 ms 2800 KB n = 50, 197881272 is a correct answer
33 Execution timed out 2037 ms 2652 KB Time limit exceeded
34 Halted 0 ms 0 KB -