답안 #809185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
809185 2023-08-05T20:07:09 Z serifefedartar Toll (BOI17_toll) C++17
100 / 100
257 ms 101496 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 50005

int dp[MAXN][LOGN][5][5];
void merge(int q[5][5], int a[5][5], int b[5][5]) {
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            for (int k = 0; k < 5; k++) {
                q[i][j] = min(q[i][j], a[i][k] + b[k][j]);
            }
        }
    }
}

int main() {
    fast
    int K, N, M, O;
    cin >> K >> N >> M >> O;

    for (int i = 0; i < MAXN; i++)
        for (int j = 0; j < LOGN; j++)
            for (int k = 0; k < 5; k++)
                for (int l = 0; l < 5; l++)
                    dp[i][j][k][l] = 1e9;

    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        dp[a/K][0][a%K][b%K] = c;
    }

    for (int i = 1; i < LOGN; i++) {
        for (int j = 0; j + (1<<i) - 1 < MAXN; j++) {
            merge(dp[j][i], dp[j][i-1], dp[j+(1<<(i-1))][i-1]);
        }
    }

    while (O--) {
        int a, b;
        cin >> a >> b;

        int h1 = a/K;
        int h2 = b/K;
        int n1 = a%K;
        int n2 = b%K;
        vector<int> ans(5, 1e9);
        ans[n1] = 0;
        for (int i = LOGN-1; i >= 0; i--) {
            if (h1 + (1<<i) <= h2) {
                vector<int> new_ans(5, 1e9);
                for (int old_rem = 0; old_rem < K; old_rem++) {
                    for (int rem = 0; rem < K; rem++) {
                        new_ans[rem] = min(new_ans[rem], ans[old_rem] + dp[h1][i][old_rem][rem]);
                    }
                }
                ans = new_ans;
                h1 += (1<<i);
            }
        }
        cout << (ans[n2] >= 1e9 ? -1 : ans[n2]) << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 99168 KB Output is correct
2 Correct 200 ms 98160 KB Output is correct
3 Correct 201 ms 98124 KB Output is correct
4 Correct 203 ms 98252 KB Output is correct
5 Correct 200 ms 98176 KB Output is correct
6 Correct 195 ms 98184 KB Output is correct
7 Correct 204 ms 98188 KB Output is correct
8 Correct 221 ms 99096 KB Output is correct
9 Correct 223 ms 99032 KB Output is correct
10 Correct 218 ms 98232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 225 ms 99768 KB Output is correct
2 Correct 199 ms 98156 KB Output is correct
3 Correct 203 ms 98160 KB Output is correct
4 Correct 198 ms 98068 KB Output is correct
5 Correct 197 ms 98160 KB Output is correct
6 Correct 199 ms 98160 KB Output is correct
7 Correct 198 ms 98232 KB Output is correct
8 Correct 205 ms 98240 KB Output is correct
9 Correct 219 ms 99044 KB Output is correct
10 Correct 229 ms 100408 KB Output is correct
11 Correct 231 ms 99844 KB Output is correct
12 Correct 219 ms 99416 KB Output is correct
13 Correct 235 ms 100544 KB Output is correct
14 Correct 222 ms 99632 KB Output is correct
15 Correct 219 ms 99348 KB Output is correct
16 Correct 217 ms 99376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 203 ms 98128 KB Output is correct
2 Correct 200 ms 98084 KB Output is correct
3 Correct 198 ms 98112 KB Output is correct
4 Correct 200 ms 98160 KB Output is correct
5 Correct 200 ms 98164 KB Output is correct
6 Correct 213 ms 98196 KB Output is correct
7 Correct 199 ms 98188 KB Output is correct
8 Correct 199 ms 98220 KB Output is correct
9 Correct 205 ms 98280 KB Output is correct
10 Correct 210 ms 98912 KB Output is correct
11 Correct 223 ms 99680 KB Output is correct
12 Correct 235 ms 100436 KB Output is correct
13 Correct 229 ms 100572 KB Output is correct
14 Correct 235 ms 99964 KB Output is correct
15 Correct 212 ms 99348 KB Output is correct
16 Correct 216 ms 99248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 203 ms 98128 KB Output is correct
2 Correct 200 ms 98084 KB Output is correct
3 Correct 198 ms 98112 KB Output is correct
4 Correct 200 ms 98160 KB Output is correct
5 Correct 200 ms 98164 KB Output is correct
6 Correct 213 ms 98196 KB Output is correct
7 Correct 199 ms 98188 KB Output is correct
8 Correct 199 ms 98220 KB Output is correct
9 Correct 205 ms 98280 KB Output is correct
10 Correct 210 ms 98912 KB Output is correct
11 Correct 223 ms 99680 KB Output is correct
12 Correct 235 ms 100436 KB Output is correct
13 Correct 229 ms 100572 KB Output is correct
14 Correct 235 ms 99964 KB Output is correct
15 Correct 212 ms 99348 KB Output is correct
16 Correct 216 ms 99248 KB Output is correct
17 Correct 218 ms 99660 KB Output is correct
18 Correct 200 ms 98160 KB Output is correct
19 Correct 199 ms 98164 KB Output is correct
20 Correct 203 ms 98156 KB Output is correct
21 Correct 209 ms 98156 KB Output is correct
22 Correct 200 ms 98160 KB Output is correct
23 Correct 203 ms 98160 KB Output is correct
24 Correct 209 ms 98208 KB Output is correct
25 Correct 202 ms 98252 KB Output is correct
26 Correct 202 ms 98224 KB Output is correct
27 Correct 230 ms 99000 KB Output is correct
28 Correct 231 ms 100364 KB Output is correct
29 Correct 235 ms 100556 KB Output is correct
30 Correct 237 ms 99916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 99168 KB Output is correct
2 Correct 200 ms 98160 KB Output is correct
3 Correct 201 ms 98124 KB Output is correct
4 Correct 203 ms 98252 KB Output is correct
5 Correct 200 ms 98176 KB Output is correct
6 Correct 195 ms 98184 KB Output is correct
7 Correct 204 ms 98188 KB Output is correct
8 Correct 221 ms 99096 KB Output is correct
9 Correct 223 ms 99032 KB Output is correct
10 Correct 218 ms 98232 KB Output is correct
11 Correct 225 ms 99768 KB Output is correct
12 Correct 199 ms 98156 KB Output is correct
13 Correct 203 ms 98160 KB Output is correct
14 Correct 198 ms 98068 KB Output is correct
15 Correct 197 ms 98160 KB Output is correct
16 Correct 199 ms 98160 KB Output is correct
17 Correct 198 ms 98232 KB Output is correct
18 Correct 205 ms 98240 KB Output is correct
19 Correct 219 ms 99044 KB Output is correct
20 Correct 229 ms 100408 KB Output is correct
21 Correct 231 ms 99844 KB Output is correct
22 Correct 219 ms 99416 KB Output is correct
23 Correct 235 ms 100544 KB Output is correct
24 Correct 222 ms 99632 KB Output is correct
25 Correct 219 ms 99348 KB Output is correct
26 Correct 217 ms 99376 KB Output is correct
27 Correct 203 ms 98128 KB Output is correct
28 Correct 200 ms 98084 KB Output is correct
29 Correct 198 ms 98112 KB Output is correct
30 Correct 200 ms 98160 KB Output is correct
31 Correct 200 ms 98164 KB Output is correct
32 Correct 213 ms 98196 KB Output is correct
33 Correct 199 ms 98188 KB Output is correct
34 Correct 199 ms 98220 KB Output is correct
35 Correct 205 ms 98280 KB Output is correct
36 Correct 210 ms 98912 KB Output is correct
37 Correct 223 ms 99680 KB Output is correct
38 Correct 235 ms 100436 KB Output is correct
39 Correct 229 ms 100572 KB Output is correct
40 Correct 235 ms 99964 KB Output is correct
41 Correct 212 ms 99348 KB Output is correct
42 Correct 216 ms 99248 KB Output is correct
43 Correct 218 ms 99660 KB Output is correct
44 Correct 200 ms 98160 KB Output is correct
45 Correct 199 ms 98164 KB Output is correct
46 Correct 203 ms 98156 KB Output is correct
47 Correct 209 ms 98156 KB Output is correct
48 Correct 200 ms 98160 KB Output is correct
49 Correct 203 ms 98160 KB Output is correct
50 Correct 209 ms 98208 KB Output is correct
51 Correct 202 ms 98252 KB Output is correct
52 Correct 202 ms 98224 KB Output is correct
53 Correct 230 ms 99000 KB Output is correct
54 Correct 231 ms 100364 KB Output is correct
55 Correct 235 ms 100556 KB Output is correct
56 Correct 237 ms 99916 KB Output is correct
57 Correct 257 ms 101496 KB Output is correct
58 Correct 223 ms 99068 KB Output is correct
59 Correct 241 ms 99932 KB Output is correct