Submission #872675

# Submission time Handle Problem Language Result Execution time Memory
872675 2023-11-13T14:14:34 Z HossamHero7 Autobus (COCI22_autobus) C++14
70 / 70
113 ms 720 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
int edge[75][75];
vector<pair<int,ll>> adj[75];
ll dp[75][75][2];
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) edge[i][j] = 1e9;
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        edge[a][b] = min(edge[a][b] , c);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) {
            if(edge[i][j] != 1e9) adj[i].push_back({j,edge[i][j]});
        }
    }
    int k,q;
    cin>>k>>q;
    k = min(k,n);
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp[i][j][0] = (i == j ? 0 : 1e18);
    for(int rem=1;rem<=k;rem++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                dp[i][j][rem&1] = dp[i][j][rem-1&1];
                for(auto [ch,c] : adj[i]) dp[i][j][rem&1] = min(dp[ch][j][rem-1&1] + c,dp[i][j][rem&1]);
            }
        }
    }
    while(q--){
        int a,b;
        cin>>a>>b;
        cout<<(dp[a][b][k&1] == 1e18 ? -1 : dp[a][b][k&1])<<endl;
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:29:47: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   29 |                 dp[i][j][rem&1] = dp[i][j][rem-1&1];
      |                                            ~~~^~
Main.cpp:30:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   30 |                 for(auto [ch,c] : adj[i]) dp[i][j][rem&1] = min(dp[ch][j][rem-1&1] + c,dp[i][j][rem&1]);
      |                          ^
Main.cpp:30:78: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   30 |                 for(auto [ch,c] : adj[i]) dp[i][j][rem&1] = min(dp[ch][j][rem-1&1] + c,dp[i][j][rem&1]);
      |                                                                           ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 5 ms 584 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 6 ms 348 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 17 ms 636 KB Output is correct
13 Correct 70 ms 592 KB Output is correct
14 Correct 71 ms 460 KB Output is correct
15 Correct 98 ms 592 KB Output is correct
16 Correct 94 ms 596 KB Output is correct
17 Correct 79 ms 596 KB Output is correct
18 Correct 70 ms 596 KB Output is correct
19 Correct 106 ms 460 KB Output is correct
20 Correct 89 ms 476 KB Output is correct
21 Correct 70 ms 472 KB Output is correct
22 Correct 76 ms 596 KB Output is correct
23 Correct 75 ms 720 KB Output is correct
24 Correct 88 ms 472 KB Output is correct
25 Correct 72 ms 456 KB Output is correct
26 Correct 79 ms 472 KB Output is correct
27 Correct 88 ms 596 KB Output is correct
28 Correct 79 ms 592 KB Output is correct
29 Correct 70 ms 592 KB Output is correct
30 Correct 78 ms 464 KB Output is correct
31 Correct 92 ms 460 KB Output is correct
32 Correct 105 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 5 ms 584 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 6 ms 348 KB Output is correct
18 Correct 5 ms 604 KB Output is correct
19 Correct 17 ms 636 KB Output is correct
20 Correct 70 ms 592 KB Output is correct
21 Correct 71 ms 460 KB Output is correct
22 Correct 98 ms 592 KB Output is correct
23 Correct 94 ms 596 KB Output is correct
24 Correct 79 ms 596 KB Output is correct
25 Correct 70 ms 596 KB Output is correct
26 Correct 106 ms 460 KB Output is correct
27 Correct 89 ms 476 KB Output is correct
28 Correct 70 ms 472 KB Output is correct
29 Correct 76 ms 596 KB Output is correct
30 Correct 75 ms 720 KB Output is correct
31 Correct 88 ms 472 KB Output is correct
32 Correct 72 ms 456 KB Output is correct
33 Correct 79 ms 472 KB Output is correct
34 Correct 88 ms 596 KB Output is correct
35 Correct 79 ms 592 KB Output is correct
36 Correct 70 ms 592 KB Output is correct
37 Correct 78 ms 464 KB Output is correct
38 Correct 92 ms 460 KB Output is correct
39 Correct 105 ms 684 KB Output is correct
40 Correct 2 ms 600 KB Output is correct
41 Correct 5 ms 604 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 9 ms 604 KB Output is correct
44 Correct 5 ms 600 KB Output is correct
45 Correct 26 ms 604 KB Output is correct
46 Correct 71 ms 460 KB Output is correct
47 Correct 86 ms 688 KB Output is correct
48 Correct 77 ms 464 KB Output is correct
49 Correct 104 ms 684 KB Output is correct
50 Correct 71 ms 460 KB Output is correct
51 Correct 78 ms 460 KB Output is correct
52 Correct 69 ms 596 KB Output is correct
53 Correct 106 ms 592 KB Output is correct
54 Correct 71 ms 600 KB Output is correct
55 Correct 72 ms 596 KB Output is correct
56 Correct 101 ms 592 KB Output is correct
57 Correct 113 ms 476 KB Output is correct
58 Correct 72 ms 476 KB Output is correct
59 Correct 86 ms 688 KB Output is correct
60 Correct 100 ms 596 KB Output is correct
61 Correct 108 ms 456 KB Output is correct
62 Correct 73 ms 600 KB Output is correct
63 Correct 77 ms 460 KB Output is correct
64 Correct 80 ms 456 KB Output is correct
65 Correct 104 ms 592 KB Output is correct