Submission #495518

# Submission time Handle Problem Language Result Execution time Memory
495518 2021-12-19T08:39:57 Z hoanghq2004 Toll (BOI17_toll) C++14
100 / 100
219 ms 199344 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1e5 + 10;

int len, n, m, q;
int f[Nmax][5][5][20];

int main() {
    ios :: sync_with_stdio(0); cin.tie(0);
    cin >> len >> n >> m >> q;
    memset(f, 60, sizeof(f));
    while (m--) {
        int u, v, w;
        cin >> u >> v >> w;
        f[u / len][u % len][v % len][0] = min(f[u / len][u % len][v % len][0], w);
    }
    for (int lg = 1; (1 << lg) <= n / len + 1; ++lg) {
        for (int i = 0; i + (1 << lg) - 1 <= n / len + 1; ++i) {
            for (int x = 0; x < len; ++x)
                for (int y = 0; y < len; ++y) {
                    for (int z = 0; z < len; ++z) {
                        f[i][x][y][lg] = min(f[i][x][y][lg], f[i][x][z][lg - 1] + f[i + (1 << lg - 1)][z][y][lg - 1]);
                    }
                }
        }
    }
    while (q--) {
        int a, b;
        cin >> a >> b;
        int x = a % len, y = b % len;
        a /= len, b /= len;
        int g[2][5][5];
        memset(g, 60, sizeof(g));
        for (int i = 0; i < 5; ++i) g[0][i][i] = 0;
        int now = 0;
        for (int i = 19; i >= 0; --i) {
            if (a + (1 << i) <= b) {
                for (int x = 0; x < 5; ++x)
                    for (int y = 0; y < 5; ++y)
                        for (int z = 0; z < 5; ++z)
                            g[now ^ 1][x][y] = min(g[now ^ 1][x][y], g[now][x][z] + f[a][z][y][i]);
                memset(g[now], 60, sizeof(g[now]));
                a += (1 << i);
                now ^= 1;
            }
        }
        if (g[now][x][y] > 1e9) cout << -1 << '\n';
        else cout << g[now][x][y] << '\n';
    }
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:24:98: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   24 |                         f[i][x][y][lg] = min(f[i][x][y][lg], f[i][x][z][lg - 1] + f[i + (1 << lg - 1)][z][y][lg - 1]);
      |                                                                                               ~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 135 ms 197016 KB Output is correct
2 Correct 77 ms 195936 KB Output is correct
3 Correct 78 ms 196116 KB Output is correct
4 Correct 77 ms 195912 KB Output is correct
5 Correct 78 ms 196008 KB Output is correct
6 Correct 80 ms 196040 KB Output is correct
7 Correct 80 ms 195956 KB Output is correct
8 Correct 140 ms 197016 KB Output is correct
9 Correct 131 ms 196804 KB Output is correct
10 Correct 123 ms 196104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 197700 KB Output is correct
2 Correct 81 ms 195988 KB Output is correct
3 Correct 76 ms 195956 KB Output is correct
4 Correct 77 ms 195988 KB Output is correct
5 Correct 77 ms 195980 KB Output is correct
6 Correct 79 ms 196060 KB Output is correct
7 Correct 90 ms 196084 KB Output is correct
8 Correct 89 ms 196036 KB Output is correct
9 Correct 121 ms 196808 KB Output is correct
10 Correct 176 ms 198332 KB Output is correct
11 Correct 152 ms 197700 KB Output is correct
12 Correct 161 ms 197240 KB Output is correct
13 Correct 149 ms 198312 KB Output is correct
14 Correct 159 ms 197464 KB Output is correct
15 Correct 126 ms 197232 KB Output is correct
16 Correct 126 ms 197220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 195924 KB Output is correct
2 Correct 87 ms 196032 KB Output is correct
3 Correct 82 ms 195960 KB Output is correct
4 Correct 80 ms 196004 KB Output is correct
5 Correct 79 ms 195972 KB Output is correct
6 Correct 86 ms 195944 KB Output is correct
7 Correct 85 ms 196024 KB Output is correct
8 Correct 84 ms 196040 KB Output is correct
9 Correct 80 ms 196028 KB Output is correct
10 Correct 102 ms 196816 KB Output is correct
11 Correct 150 ms 197672 KB Output is correct
12 Correct 162 ms 198172 KB Output is correct
13 Correct 175 ms 198428 KB Output is correct
14 Correct 169 ms 197820 KB Output is correct
15 Correct 124 ms 197192 KB Output is correct
16 Correct 130 ms 197088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 195924 KB Output is correct
2 Correct 87 ms 196032 KB Output is correct
3 Correct 82 ms 195960 KB Output is correct
4 Correct 80 ms 196004 KB Output is correct
5 Correct 79 ms 195972 KB Output is correct
6 Correct 86 ms 195944 KB Output is correct
7 Correct 85 ms 196024 KB Output is correct
8 Correct 84 ms 196040 KB Output is correct
9 Correct 80 ms 196028 KB Output is correct
10 Correct 102 ms 196816 KB Output is correct
11 Correct 150 ms 197672 KB Output is correct
12 Correct 162 ms 198172 KB Output is correct
13 Correct 175 ms 198428 KB Output is correct
14 Correct 169 ms 197820 KB Output is correct
15 Correct 124 ms 197192 KB Output is correct
16 Correct 130 ms 197088 KB Output is correct
17 Correct 151 ms 197576 KB Output is correct
18 Correct 85 ms 195924 KB Output is correct
19 Correct 78 ms 196004 KB Output is correct
20 Correct 78 ms 195964 KB Output is correct
21 Correct 79 ms 195992 KB Output is correct
22 Correct 82 ms 195980 KB Output is correct
23 Correct 84 ms 195964 KB Output is correct
24 Correct 84 ms 196072 KB Output is correct
25 Correct 85 ms 196156 KB Output is correct
26 Correct 93 ms 196060 KB Output is correct
27 Correct 116 ms 196808 KB Output is correct
28 Correct 170 ms 198228 KB Output is correct
29 Correct 179 ms 198660 KB Output is correct
30 Correct 158 ms 197792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 197016 KB Output is correct
2 Correct 77 ms 195936 KB Output is correct
3 Correct 78 ms 196116 KB Output is correct
4 Correct 77 ms 195912 KB Output is correct
5 Correct 78 ms 196008 KB Output is correct
6 Correct 80 ms 196040 KB Output is correct
7 Correct 80 ms 195956 KB Output is correct
8 Correct 140 ms 197016 KB Output is correct
9 Correct 131 ms 196804 KB Output is correct
10 Correct 123 ms 196104 KB Output is correct
11 Correct 158 ms 197700 KB Output is correct
12 Correct 81 ms 195988 KB Output is correct
13 Correct 76 ms 195956 KB Output is correct
14 Correct 77 ms 195988 KB Output is correct
15 Correct 77 ms 195980 KB Output is correct
16 Correct 79 ms 196060 KB Output is correct
17 Correct 90 ms 196084 KB Output is correct
18 Correct 89 ms 196036 KB Output is correct
19 Correct 121 ms 196808 KB Output is correct
20 Correct 176 ms 198332 KB Output is correct
21 Correct 152 ms 197700 KB Output is correct
22 Correct 161 ms 197240 KB Output is correct
23 Correct 149 ms 198312 KB Output is correct
24 Correct 159 ms 197464 KB Output is correct
25 Correct 126 ms 197232 KB Output is correct
26 Correct 126 ms 197220 KB Output is correct
27 Correct 101 ms 195924 KB Output is correct
28 Correct 87 ms 196032 KB Output is correct
29 Correct 82 ms 195960 KB Output is correct
30 Correct 80 ms 196004 KB Output is correct
31 Correct 79 ms 195972 KB Output is correct
32 Correct 86 ms 195944 KB Output is correct
33 Correct 85 ms 196024 KB Output is correct
34 Correct 84 ms 196040 KB Output is correct
35 Correct 80 ms 196028 KB Output is correct
36 Correct 102 ms 196816 KB Output is correct
37 Correct 150 ms 197672 KB Output is correct
38 Correct 162 ms 198172 KB Output is correct
39 Correct 175 ms 198428 KB Output is correct
40 Correct 169 ms 197820 KB Output is correct
41 Correct 124 ms 197192 KB Output is correct
42 Correct 130 ms 197088 KB Output is correct
43 Correct 151 ms 197576 KB Output is correct
44 Correct 85 ms 195924 KB Output is correct
45 Correct 78 ms 196004 KB Output is correct
46 Correct 78 ms 195964 KB Output is correct
47 Correct 79 ms 195992 KB Output is correct
48 Correct 82 ms 195980 KB Output is correct
49 Correct 84 ms 195964 KB Output is correct
50 Correct 84 ms 196072 KB Output is correct
51 Correct 85 ms 196156 KB Output is correct
52 Correct 93 ms 196060 KB Output is correct
53 Correct 116 ms 196808 KB Output is correct
54 Correct 170 ms 198228 KB Output is correct
55 Correct 179 ms 198660 KB Output is correct
56 Correct 158 ms 197792 KB Output is correct
57 Correct 219 ms 199344 KB Output is correct
58 Correct 136 ms 197048 KB Output is correct
59 Correct 189 ms 197788 KB Output is correct