Submission #501923

# Submission time Handle Problem Language Result Execution time Memory
501923 2022-01-04T19:28:58 Z Lobo Toll (BOI17_toll) C++17
100 / 100
200 ms 384868 KB
#include<bits/stdc++.h>
using namespace std;

/*for ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
*/

const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 105000

ll k, n, m, q, d[maxn][20][7][7];

void solve() {
    cin >> k >> n >> m >> q;

    for(ii br = 0; br <= (n-1)/k; br++) {
        for(ii pot = 0; pot <= 18; pot++) {
            for(ii i = 0; i < k; i++) {
                for(ii j = 0; j < k; j++) {
                    d[br][pot][i][j] = INFii;
                }
            }
        }
    }



    for(ii i = 0; i < m; i++) {
        ii u, v, w;
        cin >> u >> v >> w;
        d[u/k][0][u%k][v%k] = w;
    }

    for(ii pot = 1; pot <= 18; pot++) {
        for(ii br = 0; br <= (n-1)/k; br++) {
            ii mdbr = br+(1<<(pot-1));
            ii nxbr = br+(1<<pot);
            if(nxbr > (n-1)/k) {
                continue;
            }

            for(ii i = 0; i < k; i++) {
                for(ii md = 0; md < k; md++) {
                    for(ii nx = 0; nx < k; nx++) {
                        d[br][pot][i][nx] = min(d[br][pot][i][nx], d[br][pot-1][i][md] + d[mdbr][pot-1][md][nx]);
                    } 
                }
            }
        }
    }

    while(q--) {
        ii beg, des;
        cin >> beg >> des;

        vector<ll> ans;
        for(ii i = 0; i < k; i++) {
            ans.pb(INFii);
        }
        ans[beg%k] = 0;

        ii br = beg/k;
        for(ii pot = 18; pot >= 0; pot--) {
            ii nxbr = br+(1<<pot);
            if(nxbr > des/k) continue;

            vector<ll> nans;

            for(ii i = 0; i < k; i++) {
                nans.pb(INFii);
            }

            for(ii i = 0; i < k; i++) {
                for(ii nx = 0; nx < k; nx++) {
                    nans[nx] = min(nans[nx], ans[i] + d[br][pot][i][nx]);
                }
            }

            ans = nans;
            br = nxbr;
        }

        ll ans1 = ans[des%k];
        if(ans1 >= INFii) {
            cout << -1 << endl;
        }
        else {
            cout << ans1 << endl;
        }
    }

    for(ii pot = 0; pot <= 18; pot++) {
        for(ii br = 0; br <= (n-1)/k; br++) {
            ii nxbr = br+(1<<pot);
            if(nxbr > (n-1)/k) {
                continue;
            }

            for(ii i = 0; i < k; i++) {
                for(ii nx = 0; nx < k; nx++) {
                    // cout << br << " " << pot << " " << i << " " << nx << " == " << d[br][pot][i][nx] << endl;
                    // cout << br*k+i << " -> " << nxbr*k+nx << " == " << endl;
                }     
            }
        }
    }




}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    // freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);

    ii tt = 1;
    // cin >> tt;
    while(tt--) solve();

}
# Verdict Execution time Memory Grader output
1 Correct 176 ms 384836 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 4 ms 8012 KB Output is correct
6 Correct 4 ms 8012 KB Output is correct
7 Correct 4 ms 8012 KB Output is correct
8 Correct 173 ms 384840 KB Output is correct
9 Correct 200 ms 384688 KB Output is correct
10 Correct 152 ms 383996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 193756 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 8 ms 8012 KB Output is correct
8 Correct 9 ms 4220 KB Output is correct
9 Correct 184 ms 384868 KB Output is correct
10 Correct 135 ms 130396 KB Output is correct
11 Correct 131 ms 193772 KB Output is correct
12 Correct 145 ms 129448 KB Output is correct
13 Correct 79 ms 48620 KB Output is correct
14 Correct 71 ms 78532 KB Output is correct
15 Correct 59 ms 47464 KB Output is correct
16 Correct 59 ms 47556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 4 ms 8012 KB Output is correct
7 Correct 2 ms 4176 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 2252 KB Output is correct
10 Correct 180 ms 384620 KB Output is correct
11 Correct 131 ms 193612 KB Output is correct
12 Correct 116 ms 130320 KB Output is correct
13 Correct 130 ms 130452 KB Output is correct
14 Correct 117 ms 129852 KB Output is correct
15 Correct 56 ms 47512 KB Output is correct
16 Correct 58 ms 47464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 4 ms 8012 KB Output is correct
7 Correct 2 ms 4176 KB Output is correct
8 Correct 2 ms 1868 KB Output is correct
9 Correct 2 ms 2252 KB Output is correct
10 Correct 180 ms 384620 KB Output is correct
11 Correct 131 ms 193612 KB Output is correct
12 Correct 116 ms 130320 KB Output is correct
13 Correct 130 ms 130452 KB Output is correct
14 Correct 117 ms 129852 KB Output is correct
15 Correct 56 ms 47512 KB Output is correct
16 Correct 58 ms 47464 KB Output is correct
17 Correct 126 ms 193660 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 5 ms 7928 KB Output is correct
24 Correct 4 ms 4160 KB Output is correct
25 Correct 5 ms 1868 KB Output is correct
26 Correct 5 ms 2252 KB Output is correct
27 Correct 185 ms 384620 KB Output is correct
28 Correct 122 ms 130320 KB Output is correct
29 Correct 133 ms 130604 KB Output is correct
30 Correct 118 ms 129936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 176 ms 384836 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 4 ms 8012 KB Output is correct
6 Correct 4 ms 8012 KB Output is correct
7 Correct 4 ms 8012 KB Output is correct
8 Correct 173 ms 384840 KB Output is correct
9 Correct 200 ms 384688 KB Output is correct
10 Correct 152 ms 383996 KB Output is correct
11 Correct 140 ms 193756 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 8 ms 8012 KB Output is correct
18 Correct 9 ms 4220 KB Output is correct
19 Correct 184 ms 384868 KB Output is correct
20 Correct 135 ms 130396 KB Output is correct
21 Correct 131 ms 193772 KB Output is correct
22 Correct 145 ms 129448 KB Output is correct
23 Correct 79 ms 48620 KB Output is correct
24 Correct 71 ms 78532 KB Output is correct
25 Correct 59 ms 47464 KB Output is correct
26 Correct 59 ms 47556 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 316 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 4 ms 8012 KB Output is correct
33 Correct 2 ms 4176 KB Output is correct
34 Correct 2 ms 1868 KB Output is correct
35 Correct 2 ms 2252 KB Output is correct
36 Correct 180 ms 384620 KB Output is correct
37 Correct 131 ms 193612 KB Output is correct
38 Correct 116 ms 130320 KB Output is correct
39 Correct 130 ms 130452 KB Output is correct
40 Correct 117 ms 129852 KB Output is correct
41 Correct 56 ms 47512 KB Output is correct
42 Correct 58 ms 47464 KB Output is correct
43 Correct 126 ms 193660 KB Output is correct
44 Correct 0 ms 332 KB Output is correct
45 Correct 0 ms 332 KB Output is correct
46 Correct 0 ms 332 KB Output is correct
47 Correct 0 ms 332 KB Output is correct
48 Correct 0 ms 332 KB Output is correct
49 Correct 5 ms 7928 KB Output is correct
50 Correct 4 ms 4160 KB Output is correct
51 Correct 5 ms 1868 KB Output is correct
52 Correct 5 ms 2252 KB Output is correct
53 Correct 185 ms 384620 KB Output is correct
54 Correct 122 ms 130320 KB Output is correct
55 Correct 133 ms 130604 KB Output is correct
56 Correct 118 ms 129936 KB Output is correct
57 Correct 138 ms 99488 KB Output is correct
58 Correct 172 ms 384768 KB Output is correct
59 Correct 138 ms 193800 KB Output is correct