답안 #696611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696611 2023-02-07T01:21:51 Z CDuong Autobus (COCI22_autobus) C++17
70 / 70
125 ms 7476 KB
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
using namespace std;

const int mxN = 3e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;

int n, m, k, q;
int dp[75][75][75];
int single_path[75][75];
pii res[75][75];

void solve() {
    cin >> n >> m;
    memset(dp, 0x3f, sizeof dp);
    memset(single_path, 0x3f, sizeof single_path);
    for(int i = 1; i <= m; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        dp[1][u][v] = min(dp[1][u][v], w);
        single_path[u][v] = min(single_path[u][v], w);
    }
    cin >> k >> q;
    for(int turn = 2; turn <= min(n, k); ++turn)
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
                for(int k = 1; k <= n; ++k)
                    dp[turn][i][k] = min({dp[turn][i][k], mod, dp[turn - 1][i][j] + single_path[j][k]});

    while(q--) {
        int u, v; cin >> u >> v;
        if(u == v) {
            cout << "0\n";
            continue;
        }
        int ans = mod;
        for(int i = 1; i <= min(n, k); ++i)
            ans = min(ans, dp[i][u][v]);
        if(ans >= mod) cout << "-1\n";
        else cout << ans << "\n";
    }
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
    auto end = chrono::high_resolution_clock::now();
    cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
    cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2004 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1992 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2004 KB Output is correct
2 Correct 2 ms 2004 KB Output is correct
3 Correct 3 ms 2004 KB Output is correct
4 Correct 3 ms 2004 KB Output is correct
5 Correct 4 ms 2008 KB Output is correct
6 Correct 3 ms 2068 KB Output is correct
7 Correct 3 ms 2004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2004 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1992 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 12 ms 2032 KB Output is correct
8 Correct 32 ms 2004 KB Output is correct
9 Correct 4 ms 2012 KB Output is correct
10 Correct 17 ms 2004 KB Output is correct
11 Correct 7 ms 2004 KB Output is correct
12 Correct 22 ms 2004 KB Output is correct
13 Correct 87 ms 7380 KB Output is correct
14 Correct 88 ms 7272 KB Output is correct
15 Correct 112 ms 7476 KB Output is correct
16 Correct 95 ms 7316 KB Output is correct
17 Correct 89 ms 7348 KB Output is correct
18 Correct 105 ms 7244 KB Output is correct
19 Correct 115 ms 7308 KB Output is correct
20 Correct 103 ms 7452 KB Output is correct
21 Correct 86 ms 7352 KB Output is correct
22 Correct 94 ms 7348 KB Output is correct
23 Correct 95 ms 7440 KB Output is correct
24 Correct 99 ms 7372 KB Output is correct
25 Correct 91 ms 7352 KB Output is correct
26 Correct 93 ms 7352 KB Output is correct
27 Correct 100 ms 7352 KB Output is correct
28 Correct 96 ms 7316 KB Output is correct
29 Correct 88 ms 7340 KB Output is correct
30 Correct 90 ms 7308 KB Output is correct
31 Correct 98 ms 7384 KB Output is correct
32 Correct 120 ms 7348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2004 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 1 ms 1992 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 2 ms 2004 KB Output is correct
8 Correct 2 ms 2004 KB Output is correct
9 Correct 3 ms 2004 KB Output is correct
10 Correct 3 ms 2004 KB Output is correct
11 Correct 4 ms 2008 KB Output is correct
12 Correct 3 ms 2068 KB Output is correct
13 Correct 3 ms 2004 KB Output is correct
14 Correct 12 ms 2032 KB Output is correct
15 Correct 32 ms 2004 KB Output is correct
16 Correct 4 ms 2012 KB Output is correct
17 Correct 17 ms 2004 KB Output is correct
18 Correct 7 ms 2004 KB Output is correct
19 Correct 22 ms 2004 KB Output is correct
20 Correct 87 ms 7380 KB Output is correct
21 Correct 88 ms 7272 KB Output is correct
22 Correct 112 ms 7476 KB Output is correct
23 Correct 95 ms 7316 KB Output is correct
24 Correct 89 ms 7348 KB Output is correct
25 Correct 105 ms 7244 KB Output is correct
26 Correct 115 ms 7308 KB Output is correct
27 Correct 103 ms 7452 KB Output is correct
28 Correct 86 ms 7352 KB Output is correct
29 Correct 94 ms 7348 KB Output is correct
30 Correct 95 ms 7440 KB Output is correct
31 Correct 99 ms 7372 KB Output is correct
32 Correct 91 ms 7352 KB Output is correct
33 Correct 93 ms 7352 KB Output is correct
34 Correct 100 ms 7352 KB Output is correct
35 Correct 96 ms 7316 KB Output is correct
36 Correct 88 ms 7340 KB Output is correct
37 Correct 90 ms 7308 KB Output is correct
38 Correct 98 ms 7384 KB Output is correct
39 Correct 120 ms 7348 KB Output is correct
40 Correct 10 ms 2004 KB Output is correct
41 Correct 34 ms 2024 KB Output is correct
42 Correct 5 ms 2044 KB Output is correct
43 Correct 33 ms 2032 KB Output is correct
44 Correct 6 ms 2004 KB Output is correct
45 Correct 35 ms 2060 KB Output is correct
46 Correct 88 ms 7372 KB Output is correct
47 Correct 103 ms 7244 KB Output is correct
48 Correct 95 ms 7372 KB Output is correct
49 Correct 117 ms 7208 KB Output is correct
50 Correct 88 ms 7228 KB Output is correct
51 Correct 125 ms 7116 KB Output is correct
52 Correct 91 ms 7156 KB Output is correct
53 Correct 115 ms 6988 KB Output is correct
54 Correct 89 ms 6992 KB Output is correct
55 Correct 95 ms 7244 KB Output is correct
56 Correct 117 ms 7068 KB Output is correct
57 Correct 117 ms 6964 KB Output is correct
58 Correct 95 ms 6964 KB Output is correct
59 Correct 109 ms 6764 KB Output is correct
60 Correct 113 ms 6940 KB Output is correct
61 Correct 119 ms 6604 KB Output is correct
62 Correct 95 ms 6512 KB Output is correct
63 Correct 102 ms 6584 KB Output is correct
64 Correct 101 ms 6532 KB Output is correct
65 Correct 115 ms 6268 KB Output is correct