Submission #872663

# Submission time Handle Problem Language Result Execution time Memory
872663 2023-11-13T13:54:38 Z HossamHero7 Autobus (COCI22_autobus) C++14
55 / 70
1000 ms 7028 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*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 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 604 KB Output is correct
2 Correct 1 ms 476 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 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 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 3 ms 604 KB Output is correct
8 Correct 5 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 5 ms 560 KB Output is correct
12 Correct 18 ms 712 KB Output is correct
13 Correct 75 ms 6728 KB Output is correct
14 Correct 73 ms 6596 KB Output is correct
15 Correct 100 ms 6588 KB Output is correct
16 Correct 80 ms 6716 KB Output is correct
17 Correct 73 ms 6736 KB Output is correct
18 Correct 79 ms 6732 KB Output is correct
19 Correct 109 ms 6840 KB Output is correct
20 Correct 92 ms 6848 KB Output is correct
21 Correct 74 ms 6740 KB Output is correct
22 Correct 79 ms 6840 KB Output is correct
23 Correct 78 ms 6740 KB Output is correct
24 Correct 90 ms 6852 KB Output is correct
25 Correct 74 ms 6840 KB Output is correct
26 Correct 82 ms 7028 KB Output is correct
27 Correct 92 ms 6976 KB Output is correct
28 Correct 82 ms 6992 KB Output is correct
29 Correct 72 ms 6604 KB Output is correct
30 Correct 81 ms 6740 KB Output is correct
31 Correct 91 ms 6716 KB Output is correct
32 Correct 109 ms 6668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 604 KB Output is correct
8 Correct 1 ms 476 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 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 3 ms 604 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 5 ms 604 KB Output is correct
18 Correct 5 ms 560 KB Output is correct
19 Correct 18 ms 712 KB Output is correct
20 Correct 75 ms 6728 KB Output is correct
21 Correct 73 ms 6596 KB Output is correct
22 Correct 100 ms 6588 KB Output is correct
23 Correct 80 ms 6716 KB Output is correct
24 Correct 73 ms 6736 KB Output is correct
25 Correct 79 ms 6732 KB Output is correct
26 Correct 109 ms 6840 KB Output is correct
27 Correct 92 ms 6848 KB Output is correct
28 Correct 74 ms 6740 KB Output is correct
29 Correct 79 ms 6840 KB Output is correct
30 Correct 78 ms 6740 KB Output is correct
31 Correct 90 ms 6852 KB Output is correct
32 Correct 74 ms 6840 KB Output is correct
33 Correct 82 ms 7028 KB Output is correct
34 Correct 92 ms 6976 KB Output is correct
35 Correct 82 ms 6992 KB Output is correct
36 Correct 72 ms 6604 KB Output is correct
37 Correct 81 ms 6740 KB Output is correct
38 Correct 91 ms 6716 KB Output is correct
39 Correct 109 ms 6668 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 242 ms 592 KB Output is correct
42 Correct 2 ms 600 KB Output is correct
43 Correct 556 ms 608 KB Output is correct
44 Correct 5 ms 604 KB Output is correct
45 Execution timed out 1081 ms 604 KB Time limit exceeded
46 Halted 0 ms 0 KB -