Submission #544393

# Submission time Handle Problem Language Result Execution time Memory
544393 2022-04-01T20:34:01 Z huB1erTi2 Toll (BOI17_toll) C++17
100 / 100
110 ms 15560 KB
//   _|                                                _|
//   _|  _|    _|    _|    _|_|    _|_|_|      _|_|_|  _|  _|      _|_|      _|_|
//   _|_|      _|    _|  _|_|_|_|  _|    _|  _|_|      _|_|      _|_|_|_|  _|_|_|_|
//   _|  _|    _|    _|  _|        _|    _|      _|_|  _|  _|    _|        _|
//   _|    _|    _|_|_|    _|_|_|  _|_|_|    _|_|_|    _|    _|    _|_|_|    _|_|_|
//                   _|            _|
//               _|_|              _|
#include <iostream>
#include <vector>

using namespace std;

// #define DEBUG
#ifdef DEBUG
#define dassert(x) assert(x);
#define df(...) printf(__VA_ARGS__)
#else
#define dassert(x)
#define df(...)
#endif

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define ir(x, a, b) ((a) <= (x) && (x) <= (b))
#define vec vector
#define sz(x) (ll)x.size()
#define foru(i, n) for (int i = 0; (i) < (n); ++(i))
#define all(x) (x).begin(), (x).end()

typedef int64_t ll;

int read() {
    int n = 0; bool b = 0; char c = getchar();
    for (; !ir(c, '0', '9'); c = getchar()) b = (c == '-');
    for (; ir(c, '0', '9'); c = getchar()) n = 10*n + (c-'0');
    if (b) return -n;
    return n;
}

int k;
struct mat {
    vec<vec<int>> t = vec<vec<int>>(k, vec<int>(k, 1e9));
    mat operator +(const mat& other) const {
        mat res;
        for (int i = 0; i < k; ++i) {
            for (int j = 0; j < k; ++j) {
                for (int x = 0; x < k; ++x) {
                    res.t[i][j] = min(res.t[i][j], t[i][x] + other.t[x][j]);
                }
            }
        }
        return res;
    }
};

int n, m, o, base;
mat zero;
vec<mat> st;

void init() {
    for (int i = base-1; i > 0; --i) {
        st[i] = st[2*i] + st[2*i+1];
    }
}

mat get(int l, int r) {
    mat lsum = zero, rsum = zero;
    for (l += base, r += base; l < r; l /= 2, r /= 2) {
        if (l & 1) lsum = lsum + st[l++];
        if (r & 1) rsum = st[--r] + rsum;
    }
    return lsum + rsum;
}

int main() {
    df("debug mode\n");
#ifndef DEBUG
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
    cin >> k >> n >> m >> o;
    n /= k;
    
    zero = mat();
    foru (i, k) zero.t[i][i] = 0;
    
    base = 1;
    while (base <= n) base *= 2;
    st.resize(2*base);
    foru (i, m) {
        int a, b, t;
        cin >> a >> b >> t;
        st[base + a/k].t[a%k][b%k] = t;
    }
    init();
    foru (i, o) {
        int a, b;
        cin >> a >> b;
        int res = get(a/k, b/k).t[a%k][b%k];
        if (res == 1e9) cout << "-1\n";
        else cout << res << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 50 ms 11684 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 50 ms 11608 KB Output is correct
9 Correct 51 ms 11600 KB Output is correct
10 Correct 38 ms 11604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 53 ms 10100 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 8 ms 512 KB Output is correct
8 Correct 12 ms 468 KB Output is correct
9 Correct 44 ms 11620 KB Output is correct
10 Correct 74 ms 13140 KB Output is correct
11 Correct 56 ms 10092 KB Output is correct
12 Correct 58 ms 13152 KB Output is correct
13 Correct 54 ms 5332 KB Output is correct
14 Correct 37 ms 6740 KB Output is correct
15 Correct 36 ms 5320 KB Output is correct
16 Correct 36 ms 5332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 3 ms 524 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 39 ms 12356 KB Output is correct
11 Correct 42 ms 11468 KB Output is correct
12 Correct 58 ms 15300 KB Output is correct
13 Correct 63 ms 15436 KB Output is correct
14 Correct 54 ms 14920 KB Output is correct
15 Correct 30 ms 6484 KB Output is correct
16 Correct 29 ms 6568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 456 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 3 ms 524 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 39 ms 12356 KB Output is correct
11 Correct 42 ms 11468 KB Output is correct
12 Correct 58 ms 15300 KB Output is correct
13 Correct 63 ms 15436 KB Output is correct
14 Correct 54 ms 14920 KB Output is correct
15 Correct 30 ms 6484 KB Output is correct
16 Correct 29 ms 6568 KB Output is correct
17 Correct 45 ms 11596 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 5 ms 456 KB Output is correct
25 Correct 11 ms 556 KB Output is correct
26 Correct 8 ms 532 KB Output is correct
27 Correct 39 ms 12360 KB Output is correct
28 Correct 73 ms 15436 KB Output is correct
29 Correct 70 ms 15560 KB Output is correct
30 Correct 62 ms 14988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 11684 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 50 ms 11608 KB Output is correct
9 Correct 51 ms 11600 KB Output is correct
10 Correct 38 ms 11604 KB Output is correct
11 Correct 53 ms 10100 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 8 ms 512 KB Output is correct
18 Correct 12 ms 468 KB Output is correct
19 Correct 44 ms 11620 KB Output is correct
20 Correct 74 ms 13140 KB Output is correct
21 Correct 56 ms 10092 KB Output is correct
22 Correct 58 ms 13152 KB Output is correct
23 Correct 54 ms 5332 KB Output is correct
24 Correct 37 ms 6740 KB Output is correct
25 Correct 36 ms 5320 KB Output is correct
26 Correct 36 ms 5332 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 324 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 456 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 3 ms 524 KB Output is correct
35 Correct 2 ms 460 KB Output is correct
36 Correct 39 ms 12356 KB Output is correct
37 Correct 42 ms 11468 KB Output is correct
38 Correct 58 ms 15300 KB Output is correct
39 Correct 63 ms 15436 KB Output is correct
40 Correct 54 ms 14920 KB Output is correct
41 Correct 30 ms 6484 KB Output is correct
42 Correct 29 ms 6568 KB Output is correct
43 Correct 45 ms 11596 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 320 KB Output is correct
48 Correct 1 ms 320 KB Output is correct
49 Correct 4 ms 468 KB Output is correct
50 Correct 5 ms 456 KB Output is correct
51 Correct 11 ms 556 KB Output is correct
52 Correct 8 ms 532 KB Output is correct
53 Correct 39 ms 12360 KB Output is correct
54 Correct 73 ms 15436 KB Output is correct
55 Correct 70 ms 15560 KB Output is correct
56 Correct 62 ms 14988 KB Output is correct
57 Correct 110 ms 12232 KB Output is correct
58 Correct 53 ms 12520 KB Output is correct
59 Correct 70 ms 11844 KB Output is correct