답안 #529945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529945 2022-02-24T06:16:13 Z 79brue Toll (BOI17_toll) C++14
100 / 100
181 ms 101416 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int k, n, m, q;
int sps[50002][5][5][20];

int main(){
    scanf("%d %d %d %d", &k, &n, &m, &q);
    for(int i=0; i<=n; i++) for(int j=0; j<5; j++) for(int x=0; x<5; x++) for(int y=0; y<16; y++) sps[i][j][x][y] = 1e9;

    while(m--){
        int a, b, v;
        scanf("%d %d %d", &a, &b, &v);
        sps[a/k][a%k][b%k][0] = min(sps[a/k][a%k][b%k][0], v);
    }

    for(int d=0; d<16; d++){
        for(int i=0; i<=n/k; i++){
            for(int x=0; x<k; x++) for(int y=0; y<k; y++) for(int z=0; z<k; z++){
                sps[i][x][z][d+1] = min(sps[i][x][z][d+1], sps[i][x][y][d] + (i+(1<<d) >= n ? 0 : sps[i+(1<<d)][y][z][d]));
            }
        }
    }

    while(q--){
        int S, E;
        scanf("%d %d", &S, &E);
        if(S/k >= E/k){
            puts("-1");
            continue;
        }

        vector<int> dist (k, 1e9);
        dist[S%k] = 0;

        int sg = S/k, eg = E/k, gd = eg - sg;
        for(int d=0; d<16; d++){
            if((gd >> d) & 1){
                vector<int> dist2 (k, 1e9);
                for(int i=0; i<k; i++){
                    for(int j=0; j<k; j++){
                        dist2[j] = min(dist2[j], dist[i] + sps[sg][i][j][d]);
                    }
                }
                sg += 1<<d;
                dist = dist2;
            }
        }

        printf("%d\n", dist[E%k]>=1e9 ? -1 : dist[E%k]);
    }
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %d %d %d", &k, &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%d %d %d", &a, &b, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d %d", &S, &E);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 98240 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 2 ms 2252 KB Output is correct
7 Correct 3 ms 2252 KB Output is correct
8 Correct 79 ms 98264 KB Output is correct
9 Correct 79 ms 98224 KB Output is correct
10 Correct 65 ms 98256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 98252 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 296 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 296 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 6 ms 2252 KB Output is correct
8 Correct 7 ms 2380 KB Output is correct
9 Correct 78 ms 98952 KB Output is correct
10 Correct 151 ms 100412 KB Output is correct
11 Correct 121 ms 99832 KB Output is correct
12 Correct 143 ms 99524 KB Output is correct
13 Correct 108 ms 61404 KB Output is correct
14 Correct 92 ms 60360 KB Output is correct
15 Correct 82 ms 60204 KB Output is correct
16 Correct 82 ms 60196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 2224 KB Output is correct
7 Correct 2 ms 2280 KB Output is correct
8 Correct 3 ms 2252 KB Output is correct
9 Correct 4 ms 2304 KB Output is correct
10 Correct 74 ms 98872 KB Output is correct
11 Correct 114 ms 99644 KB Output is correct
12 Correct 144 ms 100256 KB Output is correct
13 Correct 152 ms 100608 KB Output is correct
14 Correct 135 ms 99900 KB Output is correct
15 Correct 81 ms 60284 KB Output is correct
16 Correct 81 ms 60120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 2224 KB Output is correct
7 Correct 2 ms 2280 KB Output is correct
8 Correct 3 ms 2252 KB Output is correct
9 Correct 4 ms 2304 KB Output is correct
10 Correct 74 ms 98872 KB Output is correct
11 Correct 114 ms 99644 KB Output is correct
12 Correct 144 ms 100256 KB Output is correct
13 Correct 152 ms 100608 KB Output is correct
14 Correct 135 ms 99900 KB Output is correct
15 Correct 81 ms 60284 KB Output is correct
16 Correct 81 ms 60120 KB Output is correct
17 Correct 123 ms 99712 KB Output is correct
18 Correct 1 ms 296 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 3 ms 2252 KB Output is correct
24 Correct 4 ms 2252 KB Output is correct
25 Correct 5 ms 2252 KB Output is correct
26 Correct 5 ms 2320 KB Output is correct
27 Correct 75 ms 98960 KB Output is correct
28 Correct 162 ms 100396 KB Output is correct
29 Correct 159 ms 100504 KB Output is correct
30 Correct 141 ms 99904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 98240 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 2 ms 2252 KB Output is correct
7 Correct 3 ms 2252 KB Output is correct
8 Correct 79 ms 98264 KB Output is correct
9 Correct 79 ms 98224 KB Output is correct
10 Correct 65 ms 98256 KB Output is correct
11 Correct 117 ms 98252 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 296 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 6 ms 2252 KB Output is correct
18 Correct 7 ms 2380 KB Output is correct
19 Correct 78 ms 98952 KB Output is correct
20 Correct 151 ms 100412 KB Output is correct
21 Correct 121 ms 99832 KB Output is correct
22 Correct 143 ms 99524 KB Output is correct
23 Correct 108 ms 61404 KB Output is correct
24 Correct 92 ms 60360 KB Output is correct
25 Correct 82 ms 60204 KB Output is correct
26 Correct 82 ms 60196 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 2 ms 2224 KB Output is correct
33 Correct 2 ms 2280 KB Output is correct
34 Correct 3 ms 2252 KB Output is correct
35 Correct 4 ms 2304 KB Output is correct
36 Correct 74 ms 98872 KB Output is correct
37 Correct 114 ms 99644 KB Output is correct
38 Correct 144 ms 100256 KB Output is correct
39 Correct 152 ms 100608 KB Output is correct
40 Correct 135 ms 99900 KB Output is correct
41 Correct 81 ms 60284 KB Output is correct
42 Correct 81 ms 60120 KB Output is correct
43 Correct 123 ms 99712 KB Output is correct
44 Correct 1 ms 296 KB Output is correct
45 Correct 1 ms 296 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 1 ms 304 KB Output is correct
49 Correct 3 ms 2252 KB Output is correct
50 Correct 4 ms 2252 KB Output is correct
51 Correct 5 ms 2252 KB Output is correct
52 Correct 5 ms 2320 KB Output is correct
53 Correct 75 ms 98960 KB Output is correct
54 Correct 162 ms 100396 KB Output is correct
55 Correct 159 ms 100504 KB Output is correct
56 Correct 141 ms 99904 KB Output is correct
57 Correct 181 ms 101416 KB Output is correct
58 Correct 81 ms 98992 KB Output is correct
59 Correct 135 ms 99844 KB Output is correct