답안 #392810

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392810 2021-04-21T19:00:06 Z Victor Toll (BOI17_toll) C++17
100 / 100
359 ms 6192 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;

const int INF = 1000000007;

int main() {
    vii graph[50001], group_jump[50001];
    int n, dist[50001], y, m, o;
    scanf("%d %d %d %d", &y, &n, &m, &o);
    const int lim = 100, k = y;

    rep(i, 0, m) {
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        graph[u].emplace_back(v, w);
    }

    for (int group = 0; (group + lim + 1) * k <= n; group += lim) {
        int start = group * k, stop = start + k, next_group = group + lim, next_start = next_group * k, next_stop = next_start + k;

        rep(region, start, stop) {
            fill(dist + start, dist + next_stop, INF);

            dist[region] = 0;

            rep(i, start, next_stop) {
                if (INF <= dist[i]) continue;

                trav(edge, graph[i]) {
                    int v, w;
                    tie(v, w) = edge;
                    dist[v] = min(dist[v], dist[i] + w);
                }
            }

            rep(i, next_start, next_stop) group_jump[region].emplace_back(i, dist[i]);
        }
    }

    rep(x, 0, o) {
        int a, b;
        scanf("%d %d", &a, &b);
        fill(dist + a, dist + b + 1, INF);

        dist[a] = 0;
        rep(i, a, b) {
            if (sz(group_jump[i]) && group_jump[i][0].first <= b) {
                while (sz(group_jump[i])) {
                    trav(edge, group_jump[i]) {
                        int v, w;
                        tie(v, w) = edge;
                        dist[v] = min(dist[v], dist[i] + w);
                    }
                    ++i;
                }
                i = group_jump[i - 1][0].first - 1;
            }

            if (INF <= dist[i]) continue;

            trav(edge, graph[i]) {
                int v, w;
                tie(v, w) = edge;
                dist[v] = min(dist[v], dist[i] + w);
            }
        }

        printf("%d\n", dist[b] < INF ? dist[b] : -1);
    }
    return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |     scanf("%d %d %d %d", &y, &n, &m, &o);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |         scanf("%d %d %d", &u, &v, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 4412 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 166 ms 4404 KB Output is correct
9 Correct 141 ms 4248 KB Output is correct
10 Correct 109 ms 3140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 208 ms 4416 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 9 ms 2636 KB Output is correct
8 Correct 23 ms 2720 KB Output is correct
9 Correct 180 ms 4548 KB Output is correct
10 Correct 297 ms 5316 KB Output is correct
11 Correct 230 ms 4464 KB Output is correct
12 Correct 191 ms 4320 KB Output is correct
13 Correct 132 ms 5436 KB Output is correct
14 Correct 89 ms 4396 KB Output is correct
15 Correct 89 ms 4036 KB Output is correct
16 Correct 86 ms 4044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 3 ms 2640 KB Output is correct
8 Correct 4 ms 2636 KB Output is correct
9 Correct 4 ms 2636 KB Output is correct
10 Correct 25 ms 4376 KB Output is correct
11 Correct 43 ms 4384 KB Output is correct
12 Correct 62 ms 5224 KB Output is correct
13 Correct 70 ms 5536 KB Output is correct
14 Correct 52 ms 4904 KB Output is correct
15 Correct 36 ms 3964 KB Output is correct
16 Correct 35 ms 3988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
6 Correct 2 ms 2636 KB Output is correct
7 Correct 3 ms 2640 KB Output is correct
8 Correct 4 ms 2636 KB Output is correct
9 Correct 4 ms 2636 KB Output is correct
10 Correct 25 ms 4376 KB Output is correct
11 Correct 43 ms 4384 KB Output is correct
12 Correct 62 ms 5224 KB Output is correct
13 Correct 70 ms 5536 KB Output is correct
14 Correct 52 ms 4904 KB Output is correct
15 Correct 36 ms 3964 KB Output is correct
16 Correct 35 ms 3988 KB Output is correct
17 Correct 87 ms 4396 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 2 ms 2636 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2636 KB Output is correct
23 Correct 5 ms 2636 KB Output is correct
24 Correct 13 ms 2688 KB Output is correct
25 Correct 26 ms 2636 KB Output is correct
26 Correct 19 ms 2720 KB Output is correct
27 Correct 63 ms 4348 KB Output is correct
28 Correct 122 ms 5188 KB Output is correct
29 Correct 143 ms 5632 KB Output is correct
30 Correct 104 ms 5044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 153 ms 4412 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Correct 2 ms 2636 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 3 ms 2636 KB Output is correct
6 Correct 3 ms 2636 KB Output is correct
7 Correct 3 ms 2636 KB Output is correct
8 Correct 166 ms 4404 KB Output is correct
9 Correct 141 ms 4248 KB Output is correct
10 Correct 109 ms 3140 KB Output is correct
11 Correct 208 ms 4416 KB Output is correct
12 Correct 2 ms 2636 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2636 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 9 ms 2636 KB Output is correct
18 Correct 23 ms 2720 KB Output is correct
19 Correct 180 ms 4548 KB Output is correct
20 Correct 297 ms 5316 KB Output is correct
21 Correct 230 ms 4464 KB Output is correct
22 Correct 191 ms 4320 KB Output is correct
23 Correct 132 ms 5436 KB Output is correct
24 Correct 89 ms 4396 KB Output is correct
25 Correct 89 ms 4036 KB Output is correct
26 Correct 86 ms 4044 KB Output is correct
27 Correct 2 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 2 ms 2636 KB Output is correct
30 Correct 2 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 2 ms 2636 KB Output is correct
33 Correct 3 ms 2640 KB Output is correct
34 Correct 4 ms 2636 KB Output is correct
35 Correct 4 ms 2636 KB Output is correct
36 Correct 25 ms 4376 KB Output is correct
37 Correct 43 ms 4384 KB Output is correct
38 Correct 62 ms 5224 KB Output is correct
39 Correct 70 ms 5536 KB Output is correct
40 Correct 52 ms 4904 KB Output is correct
41 Correct 36 ms 3964 KB Output is correct
42 Correct 35 ms 3988 KB Output is correct
43 Correct 87 ms 4396 KB Output is correct
44 Correct 2 ms 2636 KB Output is correct
45 Correct 2 ms 2636 KB Output is correct
46 Correct 2 ms 2636 KB Output is correct
47 Correct 2 ms 2636 KB Output is correct
48 Correct 2 ms 2636 KB Output is correct
49 Correct 5 ms 2636 KB Output is correct
50 Correct 13 ms 2688 KB Output is correct
51 Correct 26 ms 2636 KB Output is correct
52 Correct 19 ms 2720 KB Output is correct
53 Correct 63 ms 4348 KB Output is correct
54 Correct 122 ms 5188 KB Output is correct
55 Correct 143 ms 5632 KB Output is correct
56 Correct 104 ms 5044 KB Output is correct
57 Correct 359 ms 5572 KB Output is correct
58 Correct 159 ms 5440 KB Output is correct
59 Correct 206 ms 6192 KB Output is correct