Submission #526790

# Submission time Handle Problem Language Result Execution time Memory
526790 2022-02-16T06:37:21 Z Hydroxic_Acid Autobus (COCI22_autobus) C++14
70 / 70
202 ms 3776 KB
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define ll long long

int n, m, q, k;
ll adjm[75][75];
ll memo[75][75][75];

ll dp(ll d, ll x, ll y){
    if(x == y) return 0;
    if(d <= 0) return 1000000000000;
    if(memo[d][x][y] != -1) return memo[d][x][y];
    ll minn = 1000000000000;
    for(int i = 1; i <= n; i++){
        minn = min(minn, dp(d - 1, x, i) + adjm[i][y]);
    }
    return memo[d][x][y] = minn;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(memo, -1, sizeof(memo));
    cin >> n >> m;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            adjm[i][j] = 1000000000000;
            if(i == j) adjm[i][j] = 0;
        }
    }
    for(int i = 0; i < m; i++){
        ll a, b, t; cin >> a >> b >> t;
        adjm[a][b] = min(adjm[a][b], t);
    }
    
    cin >> k >> q;
    k = min(k, n - 1);
    for(int i = 0; i < q; i++){
        ll c, d; cin >> c >> d;
        ll ans = dp(k, c, d);
        if(ans == 1000000000000) ans = -1;
        cout << ans << endl;
    }
    
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3532 KB Output is correct
2 Correct 2 ms 3532 KB Output is correct
3 Correct 2 ms 3532 KB Output is correct
4 Correct 2 ms 3532 KB Output is correct
5 Correct 2 ms 3532 KB Output is correct
6 Correct 2 ms 3532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3660 KB Output is correct
2 Correct 16 ms 3664 KB Output is correct
3 Correct 12 ms 3660 KB Output is correct
4 Correct 10 ms 3660 KB Output is correct
5 Correct 13 ms 3668 KB Output is correct
6 Correct 11 ms 3676 KB Output is correct
7 Correct 12 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3532 KB Output is correct
2 Correct 2 ms 3532 KB Output is correct
3 Correct 2 ms 3532 KB Output is correct
4 Correct 2 ms 3532 KB Output is correct
5 Correct 2 ms 3532 KB Output is correct
6 Correct 2 ms 3532 KB Output is correct
7 Correct 43 ms 3652 KB Output is correct
8 Correct 106 ms 3640 KB Output is correct
9 Correct 14 ms 3660 KB Output is correct
10 Correct 59 ms 3660 KB Output is correct
11 Correct 26 ms 3660 KB Output is correct
12 Correct 71 ms 3660 KB Output is correct
13 Correct 92 ms 3532 KB Output is correct
14 Correct 93 ms 3660 KB Output is correct
15 Correct 174 ms 3644 KB Output is correct
16 Correct 125 ms 3636 KB Output is correct
17 Correct 95 ms 3640 KB Output is correct
18 Correct 93 ms 3660 KB Output is correct
19 Correct 202 ms 3640 KB Output is correct
20 Correct 143 ms 3640 KB Output is correct
21 Correct 97 ms 3636 KB Output is correct
22 Correct 106 ms 3652 KB Output is correct
23 Correct 125 ms 3652 KB Output is correct
24 Correct 141 ms 3640 KB Output is correct
25 Correct 106 ms 3776 KB Output is correct
26 Correct 111 ms 3640 KB Output is correct
27 Correct 120 ms 3624 KB Output is correct
28 Correct 114 ms 3636 KB Output is correct
29 Correct 99 ms 3652 KB Output is correct
30 Correct 125 ms 3636 KB Output is correct
31 Correct 167 ms 3660 KB Output is correct
32 Correct 183 ms 3648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3532 KB Output is correct
2 Correct 2 ms 3532 KB Output is correct
3 Correct 2 ms 3532 KB Output is correct
4 Correct 2 ms 3532 KB Output is correct
5 Correct 2 ms 3532 KB Output is correct
6 Correct 2 ms 3532 KB Output is correct
7 Correct 10 ms 3660 KB Output is correct
8 Correct 16 ms 3664 KB Output is correct
9 Correct 12 ms 3660 KB Output is correct
10 Correct 10 ms 3660 KB Output is correct
11 Correct 13 ms 3668 KB Output is correct
12 Correct 11 ms 3676 KB Output is correct
13 Correct 12 ms 3664 KB Output is correct
14 Correct 43 ms 3652 KB Output is correct
15 Correct 106 ms 3640 KB Output is correct
16 Correct 14 ms 3660 KB Output is correct
17 Correct 59 ms 3660 KB Output is correct
18 Correct 26 ms 3660 KB Output is correct
19 Correct 71 ms 3660 KB Output is correct
20 Correct 92 ms 3532 KB Output is correct
21 Correct 93 ms 3660 KB Output is correct
22 Correct 174 ms 3644 KB Output is correct
23 Correct 125 ms 3636 KB Output is correct
24 Correct 95 ms 3640 KB Output is correct
25 Correct 93 ms 3660 KB Output is correct
26 Correct 202 ms 3640 KB Output is correct
27 Correct 143 ms 3640 KB Output is correct
28 Correct 97 ms 3636 KB Output is correct
29 Correct 106 ms 3652 KB Output is correct
30 Correct 125 ms 3652 KB Output is correct
31 Correct 141 ms 3640 KB Output is correct
32 Correct 106 ms 3776 KB Output is correct
33 Correct 111 ms 3640 KB Output is correct
34 Correct 120 ms 3624 KB Output is correct
35 Correct 114 ms 3636 KB Output is correct
36 Correct 99 ms 3652 KB Output is correct
37 Correct 125 ms 3636 KB Output is correct
38 Correct 167 ms 3660 KB Output is correct
39 Correct 183 ms 3648 KB Output is correct
40 Correct 33 ms 3660 KB Output is correct
41 Correct 119 ms 3652 KB Output is correct
42 Correct 18 ms 3668 KB Output is correct
43 Correct 102 ms 3660 KB Output is correct
44 Correct 24 ms 3660 KB Output is correct
45 Correct 104 ms 3648 KB Output is correct
46 Correct 111 ms 3640 KB Output is correct
47 Correct 151 ms 3644 KB Output is correct
48 Correct 106 ms 3660 KB Output is correct
49 Correct 180 ms 3660 KB Output is correct
50 Correct 101 ms 3624 KB Output is correct
51 Correct 150 ms 3620 KB Output is correct
52 Correct 90 ms 3652 KB Output is correct
53 Correct 180 ms 3652 KB Output is correct
54 Correct 92 ms 3660 KB Output is correct
55 Correct 114 ms 3640 KB Output is correct
56 Correct 182 ms 3640 KB Output is correct
57 Correct 186 ms 3656 KB Output is correct
58 Correct 93 ms 3636 KB Output is correct
59 Correct 142 ms 3764 KB Output is correct
60 Correct 163 ms 3660 KB Output is correct
61 Correct 182 ms 3660 KB Output is correct
62 Correct 97 ms 3652 KB Output is correct
63 Correct 113 ms 3648 KB Output is correct
64 Correct 117 ms 3648 KB Output is correct
65 Correct 183 ms 3640 KB Output is correct