Submission #1094847

# Submission time Handle Problem Language Result Execution time Memory
1094847 2024-09-30T16:19:01 Z BLOBVISGOD Toll (BOI17_toll) C++17
100 / 100
90 ms 15744 KB
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int oo = 1e9;

struct conn{
    int s;
    vi mc; // from to
    inline int& gt(int x, int y){
        return mc[x*s+y];
    }
    conn operator+(conn b){
        conn ans;
        ans.s = s;
        ans.mc.resize(s*s,oo);
        rep(i,0,s) rep(j,0,s) rep(k,0,s) ans.gt(i,j) = min(ans.gt(i,j), gt(i,k) +b.gt(k,j));
        return ans;
    }
};

struct segtree{
    int k, n;
    conn id;
    vector<conn> a;
    segtree(vector<conn> b, int k) : k(k) {
        id.s = k;
        id.mc.resize(k*k,oo);
        rep(i,0,k) id.gt(i,i) = 0;
        n = 1;
        while(n<sz(b)) n*=2;
        a.resize(n*2,id);
        rep(i,0,sz(b)) a[i+n] = b[i];
        for(int i = n-1; i>0; --i) a[i] = a[i*2] + a[i*2+1];
    }
    conn gt(int i, int l, int r, int ql, int qr){
        if (l>=qr or r<=ql) return id;
        if (l>=ql and r<=qr) return a[i];
        int mid = (l+r)/2;
        return gt(i*2,l,mid,ql,qr) + gt(i*2+1,mid,r,ql,qr);
    }
    conn get(int l, int r) {return gt(1,0,n,l,r);}
};


int main(){
    cin.tie(NULL),cin.sync_with_stdio(false);
    
    int k,n,m,o; cin >> k >> n >> m >> o;
    int N = (n+k-1)/k + 1;
    vector<conn> conns(N);
    rep(i,0,N){
        conns[i].s = k;
        conns[i].mc.resize(k*k,oo);
    }

    while (m--){
        int a,b,t; cin >> a >> b >> t;
        int bl = a/k;
        conns[bl].gt(a%k,b%k) = min(conns[bl].gt(a%k,b%k), t);
    }

    segtree st(conns, k);
    
    while (o--){
        int a,b; cin >> a >> b;
        int ba = a/k, bb= b/k;
        auto ret = st.get(ba,bb); // halfopen
        int ans = ret.gt(a%k,b%k);
        if (ans==oo) cout << "-1\n";
        else cout << ans << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 15660 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 74 ms 15604 KB Output is correct
9 Correct 36 ms 15704 KB Output is correct
10 Correct 28 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 9040 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 6 ms 792 KB Output is correct
8 Correct 7 ms 708 KB Output is correct
9 Correct 34 ms 15616 KB Output is correct
10 Correct 48 ms 10316 KB Output is correct
11 Correct 38 ms 9296 KB Output is correct
12 Correct 37 ms 9296 KB Output is correct
13 Correct 43 ms 6736 KB Output is correct
14 Correct 26 ms 5976 KB Output is correct
15 Correct 29 ms 5520 KB Output is correct
16 Correct 33 ms 5468 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 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 22 ms 15744 KB Output is correct
11 Correct 30 ms 9064 KB Output is correct
12 Correct 33 ms 10132 KB Output is correct
13 Correct 39 ms 10576 KB Output is correct
14 Correct 29 ms 9820 KB Output is correct
15 Correct 18 ms 5468 KB Output is correct
16 Correct 19 ms 5464 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 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 22 ms 15744 KB Output is correct
11 Correct 30 ms 9064 KB Output is correct
12 Correct 33 ms 10132 KB Output is correct
13 Correct 39 ms 10576 KB Output is correct
14 Correct 29 ms 9820 KB Output is correct
15 Correct 18 ms 5468 KB Output is correct
16 Correct 19 ms 5464 KB Output is correct
17 Correct 37 ms 9052 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 4 ms 600 KB Output is correct
25 Correct 14 ms 604 KB Output is correct
26 Correct 7 ms 600 KB Output is correct
27 Correct 30 ms 15740 KB Output is correct
28 Correct 39 ms 10324 KB Output is correct
29 Correct 43 ms 10828 KB Output is correct
30 Correct 35 ms 9804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 15660 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 74 ms 15604 KB Output is correct
9 Correct 36 ms 15704 KB Output is correct
10 Correct 28 ms 14940 KB Output is correct
11 Correct 35 ms 9040 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 6 ms 792 KB Output is correct
18 Correct 7 ms 708 KB Output is correct
19 Correct 34 ms 15616 KB Output is correct
20 Correct 48 ms 10316 KB Output is correct
21 Correct 38 ms 9296 KB Output is correct
22 Correct 37 ms 9296 KB Output is correct
23 Correct 43 ms 6736 KB Output is correct
24 Correct 26 ms 5976 KB Output is correct
25 Correct 29 ms 5520 KB Output is correct
26 Correct 33 ms 5468 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 1 ms 464 KB Output is correct
36 Correct 22 ms 15744 KB Output is correct
37 Correct 30 ms 9064 KB Output is correct
38 Correct 33 ms 10132 KB Output is correct
39 Correct 39 ms 10576 KB Output is correct
40 Correct 29 ms 9820 KB Output is correct
41 Correct 18 ms 5468 KB Output is correct
42 Correct 19 ms 5464 KB Output is correct
43 Correct 37 ms 9052 KB Output is correct
44 Correct 0 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 3 ms 604 KB Output is correct
50 Correct 4 ms 600 KB Output is correct
51 Correct 14 ms 604 KB Output is correct
52 Correct 7 ms 600 KB Output is correct
53 Correct 30 ms 15740 KB Output is correct
54 Correct 39 ms 10324 KB Output is correct
55 Correct 43 ms 10828 KB Output is correct
56 Correct 35 ms 9804 KB Output is correct
57 Correct 90 ms 10068 KB Output is correct
58 Correct 36 ms 15704 KB Output is correct
59 Correct 43 ms 9552 KB Output is correct