Submission #773694

# Submission time Handle Problem Language Result Execution time Memory
773694 2023-07-05T07:51:04 Z PoonYaPat Shortcut (IOI16_shortcut) C++14
0 / 100
2000 ms 384 KB
#include "shortcut.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;

int n;
ll ans=LLONG_MAX;
vector<pii> adj[2005];


ll find_shortcut(int N, vector<int> l, vector<int> d, int c) {
    n=N;
    for (int i=0; i<n-1; ++i) {
        adj[i].push_back(pii(i+1,l[i]));
        adj[i+1].push_back(pii(i,l[i]));
    }

    vector<int> v;

    for (int i=0; i<n; ++i) {
        v.push_back(i);
        if (d[i]) {
            adj[i].push_back(pii(i+500,d[i]));
            adj[i+500].push_back(pii(i,d[i]));
            v.push_back(i+500);
        }
    }

    for (int l=0; l<n; ++l) {
        for (int r=l+1; r<n; ++r) {
            //consider express in (l,r)
            adj[l].push_back(pii(r,c));
            adj[r].push_back(pii(l,c));

            ll mmax=0;

            for (auto st : v) {
                priority_queue<pii, vector<pii>, greater<pii>> q;
                ll dis[1005];
                bool vis[1005];

                for (int i=0; i<1003; ++i) dis[i]=1e18, vis[i]=false;

                dis[st]=0;
                q.push(pii(0,st));

                while (!q.empty()) {
                    ll node=q.top().second;
                    q.pop();
                    mmax=max(mmax,dis[node]);

                    if (vis[node]) continue;
                    vis[node]=true;

                    for (auto s : adj[node]) {
                        if (dis[s.first]>dis[node]+s.second) {
                            dis[s.first]=dis[node]+s.second;
                            q.push(pii(dis[s.first],s.first));
                        }
                    }
                }
            }
            ans=min(ans,mmax);

            adj[l].pop_back();
            adj[r].pop_back();
        }
    }

    ll mmax=0;

    for (auto st : v) {
        priority_queue<pii, vector<pii>, greater<pii>> q;
        ll dis[2005];
        bool vis[2005];

        for (int i=0; i<2003; ++i) dis[i]=1e18, vis[i]=false;

        dis[st]=0;
        q.push(pii(0,st));

        while (!q.empty()) {
            ll node=q.top().second;
            q.pop();
            mmax=max(mmax,dis[node]);

            if (vis[node]) continue;
            vis[node]=true;

            for (auto s : adj[node]) {
                if (dis[s.first]>dis[node]+s.second) {
                    dis[s.first]=dis[node]+s.second;
                    q.push(pii(dis[s.first],s.first));
                }
            }
        }
    }
    ans=min(ans,mmax);

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 352 KB n = 3, 4 is a correct answer
5 Correct 1 ms 340 KB n = 2, 62 is a correct answer
6 Correct 0 ms 340 KB n = 2, 3 is a correct answer
7 Correct 1 ms 340 KB n = 3, 29 is a correct answer
8 Correct 1 ms 340 KB n = 2, 3 is a correct answer
9 Correct 0 ms 344 KB n = 2, 3 is a correct answer
10 Correct 1 ms 340 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 340 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 384 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 340 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 340 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 340 KB n = 10, 1000000343 is a correct answer
18 Correct 2 ms 340 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 340 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 340 KB n = 5, 12 is a correct answer
21 Correct 0 ms 340 KB n = 5, 25 is a correct answer
22 Correct 1 ms 340 KB n = 2, 122 is a correct answer
23 Correct 1 ms 340 KB n = 10, 117 is a correct answer
24 Correct 1 ms 344 KB n = 10, 336 is a correct answer
25 Correct 1 ms 340 KB n = 10, 438 is a correct answer
26 Correct 1 ms 340 KB n = 10, 206 is a correct answer
27 Correct 2 ms 348 KB n = 10, 636 is a correct answer
28 Correct 1 ms 340 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 340 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 340 KB n = 10, 3112 is a correct answer
31 Execution timed out 2062 ms 340 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 352 KB n = 3, 4 is a correct answer
5 Correct 1 ms 340 KB n = 2, 62 is a correct answer
6 Correct 0 ms 340 KB n = 2, 3 is a correct answer
7 Correct 1 ms 340 KB n = 3, 29 is a correct answer
8 Correct 1 ms 340 KB n = 2, 3 is a correct answer
9 Correct 0 ms 344 KB n = 2, 3 is a correct answer
10 Correct 1 ms 340 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 340 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 384 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 340 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 340 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 340 KB n = 10, 1000000343 is a correct answer
18 Correct 2 ms 340 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 340 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 340 KB n = 5, 12 is a correct answer
21 Correct 0 ms 340 KB n = 5, 25 is a correct answer
22 Correct 1 ms 340 KB n = 2, 122 is a correct answer
23 Correct 1 ms 340 KB n = 10, 117 is a correct answer
24 Correct 1 ms 344 KB n = 10, 336 is a correct answer
25 Correct 1 ms 340 KB n = 10, 438 is a correct answer
26 Correct 1 ms 340 KB n = 10, 206 is a correct answer
27 Correct 2 ms 348 KB n = 10, 636 is a correct answer
28 Correct 1 ms 340 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 340 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 340 KB n = 10, 3112 is a correct answer
31 Execution timed out 2062 ms 340 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 352 KB n = 3, 4 is a correct answer
5 Correct 1 ms 340 KB n = 2, 62 is a correct answer
6 Correct 0 ms 340 KB n = 2, 3 is a correct answer
7 Correct 1 ms 340 KB n = 3, 29 is a correct answer
8 Correct 1 ms 340 KB n = 2, 3 is a correct answer
9 Correct 0 ms 344 KB n = 2, 3 is a correct answer
10 Correct 1 ms 340 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 340 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 384 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 340 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 340 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 340 KB n = 10, 1000000343 is a correct answer
18 Correct 2 ms 340 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 340 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 340 KB n = 5, 12 is a correct answer
21 Correct 0 ms 340 KB n = 5, 25 is a correct answer
22 Correct 1 ms 340 KB n = 2, 122 is a correct answer
23 Correct 1 ms 340 KB n = 10, 117 is a correct answer
24 Correct 1 ms 344 KB n = 10, 336 is a correct answer
25 Correct 1 ms 340 KB n = 10, 438 is a correct answer
26 Correct 1 ms 340 KB n = 10, 206 is a correct answer
27 Correct 2 ms 348 KB n = 10, 636 is a correct answer
28 Correct 1 ms 340 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 340 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 340 KB n = 10, 3112 is a correct answer
31 Execution timed out 2062 ms 340 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 352 KB n = 3, 4 is a correct answer
5 Correct 1 ms 340 KB n = 2, 62 is a correct answer
6 Correct 0 ms 340 KB n = 2, 3 is a correct answer
7 Correct 1 ms 340 KB n = 3, 29 is a correct answer
8 Correct 1 ms 340 KB n = 2, 3 is a correct answer
9 Correct 0 ms 344 KB n = 2, 3 is a correct answer
10 Correct 1 ms 340 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 340 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 384 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 340 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 340 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 340 KB n = 10, 1000000343 is a correct answer
18 Correct 2 ms 340 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 340 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 340 KB n = 5, 12 is a correct answer
21 Correct 0 ms 340 KB n = 5, 25 is a correct answer
22 Correct 1 ms 340 KB n = 2, 122 is a correct answer
23 Correct 1 ms 340 KB n = 10, 117 is a correct answer
24 Correct 1 ms 344 KB n = 10, 336 is a correct answer
25 Correct 1 ms 340 KB n = 10, 438 is a correct answer
26 Correct 1 ms 340 KB n = 10, 206 is a correct answer
27 Correct 2 ms 348 KB n = 10, 636 is a correct answer
28 Correct 1 ms 340 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 340 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 340 KB n = 10, 3112 is a correct answer
31 Execution timed out 2062 ms 340 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 352 KB n = 3, 4 is a correct answer
5 Correct 1 ms 340 KB n = 2, 62 is a correct answer
6 Correct 0 ms 340 KB n = 2, 3 is a correct answer
7 Correct 1 ms 340 KB n = 3, 29 is a correct answer
8 Correct 1 ms 340 KB n = 2, 3 is a correct answer
9 Correct 0 ms 344 KB n = 2, 3 is a correct answer
10 Correct 1 ms 340 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 340 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 384 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 340 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 340 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 340 KB n = 10, 1000000343 is a correct answer
18 Correct 2 ms 340 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 340 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 340 KB n = 5, 12 is a correct answer
21 Correct 0 ms 340 KB n = 5, 25 is a correct answer
22 Correct 1 ms 340 KB n = 2, 122 is a correct answer
23 Correct 1 ms 340 KB n = 10, 117 is a correct answer
24 Correct 1 ms 344 KB n = 10, 336 is a correct answer
25 Correct 1 ms 340 KB n = 10, 438 is a correct answer
26 Correct 1 ms 340 KB n = 10, 206 is a correct answer
27 Correct 2 ms 348 KB n = 10, 636 is a correct answer
28 Correct 1 ms 340 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 340 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 340 KB n = 10, 3112 is a correct answer
31 Execution timed out 2062 ms 340 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 352 KB n = 3, 4 is a correct answer
5 Correct 1 ms 340 KB n = 2, 62 is a correct answer
6 Correct 0 ms 340 KB n = 2, 3 is a correct answer
7 Correct 1 ms 340 KB n = 3, 29 is a correct answer
8 Correct 1 ms 340 KB n = 2, 3 is a correct answer
9 Correct 0 ms 344 KB n = 2, 3 is a correct answer
10 Correct 1 ms 340 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 340 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 384 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 340 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 340 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 340 KB n = 10, 1000000343 is a correct answer
18 Correct 2 ms 340 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 340 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 340 KB n = 5, 12 is a correct answer
21 Correct 0 ms 340 KB n = 5, 25 is a correct answer
22 Correct 1 ms 340 KB n = 2, 122 is a correct answer
23 Correct 1 ms 340 KB n = 10, 117 is a correct answer
24 Correct 1 ms 344 KB n = 10, 336 is a correct answer
25 Correct 1 ms 340 KB n = 10, 438 is a correct answer
26 Correct 1 ms 340 KB n = 10, 206 is a correct answer
27 Correct 2 ms 348 KB n = 10, 636 is a correct answer
28 Correct 1 ms 340 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 340 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 340 KB n = 10, 3112 is a correct answer
31 Execution timed out 2062 ms 340 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 352 KB n = 3, 4 is a correct answer
5 Correct 1 ms 340 KB n = 2, 62 is a correct answer
6 Correct 0 ms 340 KB n = 2, 3 is a correct answer
7 Correct 1 ms 340 KB n = 3, 29 is a correct answer
8 Correct 1 ms 340 KB n = 2, 3 is a correct answer
9 Correct 0 ms 344 KB n = 2, 3 is a correct answer
10 Correct 1 ms 340 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 340 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 384 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 340 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 340 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 340 KB n = 10, 1000000343 is a correct answer
18 Correct 2 ms 340 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 340 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 340 KB n = 5, 12 is a correct answer
21 Correct 0 ms 340 KB n = 5, 25 is a correct answer
22 Correct 1 ms 340 KB n = 2, 122 is a correct answer
23 Correct 1 ms 340 KB n = 10, 117 is a correct answer
24 Correct 1 ms 344 KB n = 10, 336 is a correct answer
25 Correct 1 ms 340 KB n = 10, 438 is a correct answer
26 Correct 1 ms 340 KB n = 10, 206 is a correct answer
27 Correct 2 ms 348 KB n = 10, 636 is a correct answer
28 Correct 1 ms 340 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 340 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 340 KB n = 10, 3112 is a correct answer
31 Execution timed out 2062 ms 340 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n = 4, 80 is a correct answer
2 Correct 1 ms 340 KB n = 9, 110 is a correct answer
3 Correct 1 ms 340 KB n = 4, 21 is a correct answer
4 Correct 0 ms 352 KB n = 3, 4 is a correct answer
5 Correct 1 ms 340 KB n = 2, 62 is a correct answer
6 Correct 0 ms 340 KB n = 2, 3 is a correct answer
7 Correct 1 ms 340 KB n = 3, 29 is a correct answer
8 Correct 1 ms 340 KB n = 2, 3 is a correct answer
9 Correct 0 ms 344 KB n = 2, 3 is a correct answer
10 Correct 1 ms 340 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 340 KB n = 2, 3000000000 is a correct answer
12 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 340 KB n = 3, 3000000000 is a correct answer
14 Correct 1 ms 384 KB n = 4, 3000000001 is a correct answer
15 Correct 0 ms 340 KB n = 4, 4000000000 is a correct answer
16 Correct 0 ms 340 KB n = 5, 4000000000 is a correct answer
17 Correct 2 ms 340 KB n = 10, 1000000343 is a correct answer
18 Correct 2 ms 340 KB n = 10, 3189 is a correct answer
19 Correct 1 ms 340 KB n = 10, 7000000000 is a correct answer
20 Correct 1 ms 340 KB n = 5, 12 is a correct answer
21 Correct 0 ms 340 KB n = 5, 25 is a correct answer
22 Correct 1 ms 340 KB n = 2, 122 is a correct answer
23 Correct 1 ms 340 KB n = 10, 117 is a correct answer
24 Correct 1 ms 344 KB n = 10, 336 is a correct answer
25 Correct 1 ms 340 KB n = 10, 438 is a correct answer
26 Correct 1 ms 340 KB n = 10, 206 is a correct answer
27 Correct 2 ms 348 KB n = 10, 636 is a correct answer
28 Correct 1 ms 340 KB n = 4, 2399 is a correct answer
29 Correct 1 ms 340 KB n = 10, 10992 is a correct answer
30 Correct 1 ms 340 KB n = 10, 3112 is a correct answer
31 Execution timed out 2062 ms 340 KB Time limit exceeded
32 Halted 0 ms 0 KB -