답안 #536664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536664 2022-03-13T17:51:41 Z KiriLL1ca Toll (BOI17_toll) C++14
100 / 100
321 ms 86956 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fr first
#define sc second
#define endl '\n'
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pw(x) (1ll << x)

#pragma GCC optimize ("-O3")
#pragma GCC optimize ("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double ld;

template <typename T> inline bool umax (T &a, const T &b) { return (a < b ? a = b, 1 : 0); }
template <typename T> inline bool umin (T &a, const T &b) { return (a > b ? a = b, 1 : 0); }

template <typename T>
using oset = tree<T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 5e4 + 100;
const int K = 5;
const int LG = 17;

int up[N][K][K][LG];

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for (int i = 0; i < N; i++) for (int j = 0; j < K; j++) for (int k = 0; k < K; k++) for (int q = 0; q < LG; q++) up[i][j][k][q] = 1e9;

    int k, n, m, q; cin >> k >> n >> m >> q;
    for (int i = 0; i < m; i++) {
        int a, b, c; cin >> a >> b >> c;
        umin(up[a / k][a % k][b % k][0], c);
    }
    for (int d = 1; d < LG; d++) {
        for (int i = 0; i < N; i++) {
            if (i + pw(d) >= N) break;
            for (int x = 0; x < k; x++) {
                vector <int> dst (k, 1e9);
                for (int y = 0; y < k; y++) {
                    for (int z = 0; z < k; z++) {
                        umin(dst[z], up[i][x][y][d - 1] + up[i + pw(d - 1)][y][z][d - 1]);
                    }
                }
                for (int y = 0; y < k; y++) up[i][x][y][d] = dst[y];
            }
        }
    }
    while (q--) {
        int a, b; cin >> a >> b;
        vector <int> dst (k, 1e9);
        dst[a % k] = 0;
        int ba = a / k, bb = b / k;
        for (int j = LG - 1; j >= 0; j--) {
            if (ba + pw(j) > bb) continue;
            vector <int> dstt (k, 1e9);
            for (int x = 0; x < k; x++) {
                for (int y = 0; y < k; y++) {
                    umin(dstt[y], dst[x] + up[ba][x][y][j]);
                }
            }
            dst = dstt;
            ba += pw(j);
        }
        cout << (dst[b % k] == 1e9 ? -1 : dst[b % k]) << endl;
    }
    return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:53:71: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   53 |                         umin(dst[z], up[i][x][y][d - 1] + up[i + pw(d - 1)][y][z][d - 1]);
      |                                                                     ~~^~~
toll.cpp:11:23: note: in definition of macro 'pw'
   11 | #define pw(x) (1ll << x)
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 83788 KB Output is correct
2 Correct 48 ms 83568 KB Output is correct
3 Correct 51 ms 83576 KB Output is correct
4 Correct 54 ms 83644 KB Output is correct
5 Correct 51 ms 83568 KB Output is correct
6 Correct 53 ms 83652 KB Output is correct
7 Correct 56 ms 83660 KB Output is correct
8 Correct 91 ms 83688 KB Output is correct
9 Correct 82 ms 83740 KB Output is correct
10 Correct 58 ms 83676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 83812 KB Output is correct
2 Correct 50 ms 83532 KB Output is correct
3 Correct 140 ms 83576 KB Output is correct
4 Correct 188 ms 83644 KB Output is correct
5 Correct 229 ms 83580 KB Output is correct
6 Correct 260 ms 83596 KB Output is correct
7 Correct 52 ms 83720 KB Output is correct
8 Correct 144 ms 83720 KB Output is correct
9 Correct 73 ms 84516 KB Output is correct
10 Correct 286 ms 85884 KB Output is correct
11 Correct 220 ms 85344 KB Output is correct
12 Correct 221 ms 84848 KB Output is correct
13 Correct 316 ms 86056 KB Output is correct
14 Correct 220 ms 85068 KB Output is correct
15 Correct 274 ms 84808 KB Output is correct
16 Correct 295 ms 84852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 83580 KB Output is correct
2 Correct 146 ms 83640 KB Output is correct
3 Correct 219 ms 83632 KB Output is correct
4 Correct 226 ms 83596 KB Output is correct
5 Correct 266 ms 83640 KB Output is correct
6 Correct 69 ms 83608 KB Output is correct
7 Correct 145 ms 83552 KB Output is correct
8 Correct 251 ms 83616 KB Output is correct
9 Correct 240 ms 83536 KB Output is correct
10 Correct 68 ms 83600 KB Output is correct
11 Correct 186 ms 83604 KB Output is correct
12 Correct 248 ms 83756 KB Output is correct
13 Correct 245 ms 83740 KB Output is correct
14 Correct 237 ms 83636 KB Output is correct
15 Correct 321 ms 83640 KB Output is correct
16 Correct 283 ms 83640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 83580 KB Output is correct
2 Correct 146 ms 83640 KB Output is correct
3 Correct 219 ms 83632 KB Output is correct
4 Correct 226 ms 83596 KB Output is correct
5 Correct 266 ms 83640 KB Output is correct
6 Correct 69 ms 83608 KB Output is correct
7 Correct 145 ms 83552 KB Output is correct
8 Correct 251 ms 83616 KB Output is correct
9 Correct 240 ms 83536 KB Output is correct
10 Correct 68 ms 83600 KB Output is correct
11 Correct 186 ms 83604 KB Output is correct
12 Correct 248 ms 83756 KB Output is correct
13 Correct 245 ms 83740 KB Output is correct
14 Correct 237 ms 83636 KB Output is correct
15 Correct 321 ms 83640 KB Output is correct
16 Correct 283 ms 83640 KB Output is correct
17 Correct 188 ms 83568 KB Output is correct
18 Correct 54 ms 83540 KB Output is correct
19 Correct 148 ms 83636 KB Output is correct
20 Correct 188 ms 83632 KB Output is correct
21 Correct 230 ms 83636 KB Output is correct
22 Correct 250 ms 83636 KB Output is correct
23 Correct 69 ms 83532 KB Output is correct
24 Correct 151 ms 83668 KB Output is correct
25 Correct 261 ms 83648 KB Output is correct
26 Correct 231 ms 83536 KB Output is correct
27 Correct 76 ms 83640 KB Output is correct
28 Correct 240 ms 83636 KB Output is correct
29 Correct 267 ms 83640 KB Output is correct
30 Correct 237 ms 83636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 83788 KB Output is correct
2 Correct 48 ms 83568 KB Output is correct
3 Correct 51 ms 83576 KB Output is correct
4 Correct 54 ms 83644 KB Output is correct
5 Correct 51 ms 83568 KB Output is correct
6 Correct 53 ms 83652 KB Output is correct
7 Correct 56 ms 83660 KB Output is correct
8 Correct 91 ms 83688 KB Output is correct
9 Correct 82 ms 83740 KB Output is correct
10 Correct 58 ms 83676 KB Output is correct
11 Correct 195 ms 83812 KB Output is correct
12 Correct 50 ms 83532 KB Output is correct
13 Correct 140 ms 83576 KB Output is correct
14 Correct 188 ms 83644 KB Output is correct
15 Correct 229 ms 83580 KB Output is correct
16 Correct 260 ms 83596 KB Output is correct
17 Correct 52 ms 83720 KB Output is correct
18 Correct 144 ms 83720 KB Output is correct
19 Correct 73 ms 84516 KB Output is correct
20 Correct 286 ms 85884 KB Output is correct
21 Correct 220 ms 85344 KB Output is correct
22 Correct 221 ms 84848 KB Output is correct
23 Correct 316 ms 86056 KB Output is correct
24 Correct 220 ms 85068 KB Output is correct
25 Correct 274 ms 84808 KB Output is correct
26 Correct 295 ms 84852 KB Output is correct
27 Correct 49 ms 83580 KB Output is correct
28 Correct 146 ms 83640 KB Output is correct
29 Correct 219 ms 83632 KB Output is correct
30 Correct 226 ms 83596 KB Output is correct
31 Correct 266 ms 83640 KB Output is correct
32 Correct 69 ms 83608 KB Output is correct
33 Correct 145 ms 83552 KB Output is correct
34 Correct 251 ms 83616 KB Output is correct
35 Correct 240 ms 83536 KB Output is correct
36 Correct 68 ms 83600 KB Output is correct
37 Correct 186 ms 83604 KB Output is correct
38 Correct 248 ms 83756 KB Output is correct
39 Correct 245 ms 83740 KB Output is correct
40 Correct 237 ms 83636 KB Output is correct
41 Correct 321 ms 83640 KB Output is correct
42 Correct 283 ms 83640 KB Output is correct
43 Correct 188 ms 83568 KB Output is correct
44 Correct 54 ms 83540 KB Output is correct
45 Correct 148 ms 83636 KB Output is correct
46 Correct 188 ms 83632 KB Output is correct
47 Correct 230 ms 83636 KB Output is correct
48 Correct 250 ms 83636 KB Output is correct
49 Correct 69 ms 83532 KB Output is correct
50 Correct 151 ms 83668 KB Output is correct
51 Correct 261 ms 83648 KB Output is correct
52 Correct 231 ms 83536 KB Output is correct
53 Correct 76 ms 83640 KB Output is correct
54 Correct 240 ms 83636 KB Output is correct
55 Correct 267 ms 83640 KB Output is correct
56 Correct 237 ms 83636 KB Output is correct
57 Correct 317 ms 86956 KB Output is correct
58 Correct 84 ms 84556 KB Output is correct
59 Correct 194 ms 85364 KB Output is correct