답안 #476234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476234 2021-09-25T13:32:16 Z Karliver Toll (BOI17_toll) C++14
100 / 100
137 ms 86896 KB
    
#include <bits/stdc++.h>

#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
#define all(v) (v).begin(), (v).end()
using namespace  std;
#define forn(i,n) for (int i = 0; i < (n); ++i)
#define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
using ll = long long;
int mod = (ll)1e9 + 7;
#define PI acos(-1)
typedef pair<int, int> pairs;

const int INF = 1e9 + 1;
const int N = 5e4 + 100;
const double eps = 1e-7;

template <class T> using V = vector<T>;  
template <class T> using VV = V<V<T>>;  

template <typename XPAX>
void ckma(XPAX &x, XPAX y) {
    x = (x < y ? y : x);
}
template <typename XPAX>
void ckmi(XPAX &x, XPAX y) {
    x = (x > y ? y : x);
}
int n, k, m, q;
const int MX = 17;
int F[N][MX][5][5], tmp[5][5], ans[5][5];

void comb(int tar[5][5], int a[5][5], int b[5][5]) {
    for(int x = 0;x < k;++x)
        for(int y = 0;y < k;++y)
            for(int z = 0;z < k;++z)
                tar[x][y] = min(tar[x][y], a[x][z] + b[z][y]);
}

void solve() {


    
    cin >> k >> n >> m >> q;

    memset(F, 0x3f, sizeof F);
    while(m--) {
        int a, b, t;
        cin >> a >> b >> t;
        F[a / k][0][a % k][b % k] = t;
    }

    for(int j = 1;j < MX;++j) {
        for(int i = 0;i + (1 << j) < (n + k - 1) / k;++i) {
            comb(F[i][j], F[i][j - 1], F[i + (1 << j - 1)][j - 1]);
        }
    }

    while(q--) {
        int a, b;
        cin >> a >> b;
        memset(ans, 0x3f, sizeof(ans));
        forn(i, 5) ans[i][i] = 0;
        for(int cur = a / k, T = b / k,i = MX - 1;~i;--i) {
            if(cur + (1 << i) <= T) {
                memset(tmp, 0x3f, sizeof tmp);
                comb(tmp, ans, F[cur][i]);
                memcpy(ans, tmp, sizeof ans);
                cur += 1 << i;
            }
        }
        cout << (ans[a % k][b % k] == 0x3f3f3f3f ? -1 : ans[a % k][b % k]) << '\n';
    }
    

}
void test_case() {
    int t;
    cin >> t;
    forn(p, t) {

        //cout << "Case #" << p + 1 << ": ";
        solve();
    }
}
int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Compilation message

toll.cpp: In function 'void solve()':
toll.cpp:55:54: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   55 |             comb(F[i][j], F[i][j - 1], F[i + (1 << j - 1)][j - 1]);
      |                                                    ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 84560 KB Output is correct
2 Correct 38 ms 83524 KB Output is correct
3 Correct 33 ms 83516 KB Output is correct
4 Correct 34 ms 83544 KB Output is correct
5 Correct 33 ms 83564 KB Output is correct
6 Correct 33 ms 83644 KB Output is correct
7 Correct 33 ms 83560 KB Output is correct
8 Correct 73 ms 84540 KB Output is correct
9 Correct 90 ms 84524 KB Output is correct
10 Correct 56 ms 83692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 101 ms 85188 KB Output is correct
2 Correct 32 ms 83532 KB Output is correct
3 Correct 33 ms 83540 KB Output is correct
4 Correct 36 ms 83600 KB Output is correct
5 Correct 33 ms 83628 KB Output is correct
6 Correct 32 ms 83524 KB Output is correct
7 Correct 35 ms 83620 KB Output is correct
8 Correct 43 ms 83732 KB Output is correct
9 Correct 84 ms 84460 KB Output is correct
10 Correct 109 ms 85956 KB Output is correct
11 Correct 94 ms 85408 KB Output is correct
12 Correct 99 ms 84900 KB Output is correct
13 Correct 104 ms 86136 KB Output is correct
14 Correct 81 ms 85052 KB Output is correct
15 Correct 81 ms 84804 KB Output is correct
16 Correct 75 ms 84812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 83532 KB Output is correct
2 Correct 36 ms 83608 KB Output is correct
3 Correct 37 ms 83600 KB Output is correct
4 Correct 35 ms 83536 KB Output is correct
5 Correct 36 ms 83620 KB Output is correct
6 Correct 34 ms 83620 KB Output is correct
7 Correct 41 ms 83632 KB Output is correct
8 Correct 33 ms 83712 KB Output is correct
9 Correct 43 ms 83680 KB Output is correct
10 Correct 66 ms 84392 KB Output is correct
11 Correct 90 ms 85156 KB Output is correct
12 Correct 100 ms 85796 KB Output is correct
13 Correct 107 ms 86056 KB Output is correct
14 Correct 114 ms 85444 KB Output is correct
15 Correct 80 ms 84744 KB Output is correct
16 Correct 64 ms 84772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 83532 KB Output is correct
2 Correct 36 ms 83608 KB Output is correct
3 Correct 37 ms 83600 KB Output is correct
4 Correct 35 ms 83536 KB Output is correct
5 Correct 36 ms 83620 KB Output is correct
6 Correct 34 ms 83620 KB Output is correct
7 Correct 41 ms 83632 KB Output is correct
8 Correct 33 ms 83712 KB Output is correct
9 Correct 43 ms 83680 KB Output is correct
10 Correct 66 ms 84392 KB Output is correct
11 Correct 90 ms 85156 KB Output is correct
12 Correct 100 ms 85796 KB Output is correct
13 Correct 107 ms 86056 KB Output is correct
14 Correct 114 ms 85444 KB Output is correct
15 Correct 80 ms 84744 KB Output is correct
16 Correct 64 ms 84772 KB Output is correct
17 Correct 82 ms 85104 KB Output is correct
18 Correct 32 ms 83592 KB Output is correct
19 Correct 41 ms 83520 KB Output is correct
20 Correct 38 ms 83532 KB Output is correct
21 Correct 37 ms 83608 KB Output is correct
22 Correct 36 ms 83532 KB Output is correct
23 Correct 37 ms 83584 KB Output is correct
24 Correct 38 ms 83652 KB Output is correct
25 Correct 35 ms 83704 KB Output is correct
26 Correct 35 ms 83788 KB Output is correct
27 Correct 70 ms 84476 KB Output is correct
28 Correct 110 ms 85788 KB Output is correct
29 Correct 112 ms 86084 KB Output is correct
30 Correct 100 ms 85556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 84560 KB Output is correct
2 Correct 38 ms 83524 KB Output is correct
3 Correct 33 ms 83516 KB Output is correct
4 Correct 34 ms 83544 KB Output is correct
5 Correct 33 ms 83564 KB Output is correct
6 Correct 33 ms 83644 KB Output is correct
7 Correct 33 ms 83560 KB Output is correct
8 Correct 73 ms 84540 KB Output is correct
9 Correct 90 ms 84524 KB Output is correct
10 Correct 56 ms 83692 KB Output is correct
11 Correct 101 ms 85188 KB Output is correct
12 Correct 32 ms 83532 KB Output is correct
13 Correct 33 ms 83540 KB Output is correct
14 Correct 36 ms 83600 KB Output is correct
15 Correct 33 ms 83628 KB Output is correct
16 Correct 32 ms 83524 KB Output is correct
17 Correct 35 ms 83620 KB Output is correct
18 Correct 43 ms 83732 KB Output is correct
19 Correct 84 ms 84460 KB Output is correct
20 Correct 109 ms 85956 KB Output is correct
21 Correct 94 ms 85408 KB Output is correct
22 Correct 99 ms 84900 KB Output is correct
23 Correct 104 ms 86136 KB Output is correct
24 Correct 81 ms 85052 KB Output is correct
25 Correct 81 ms 84804 KB Output is correct
26 Correct 75 ms 84812 KB Output is correct
27 Correct 33 ms 83532 KB Output is correct
28 Correct 36 ms 83608 KB Output is correct
29 Correct 37 ms 83600 KB Output is correct
30 Correct 35 ms 83536 KB Output is correct
31 Correct 36 ms 83620 KB Output is correct
32 Correct 34 ms 83620 KB Output is correct
33 Correct 41 ms 83632 KB Output is correct
34 Correct 33 ms 83712 KB Output is correct
35 Correct 43 ms 83680 KB Output is correct
36 Correct 66 ms 84392 KB Output is correct
37 Correct 90 ms 85156 KB Output is correct
38 Correct 100 ms 85796 KB Output is correct
39 Correct 107 ms 86056 KB Output is correct
40 Correct 114 ms 85444 KB Output is correct
41 Correct 80 ms 84744 KB Output is correct
42 Correct 64 ms 84772 KB Output is correct
43 Correct 82 ms 85104 KB Output is correct
44 Correct 32 ms 83592 KB Output is correct
45 Correct 41 ms 83520 KB Output is correct
46 Correct 38 ms 83532 KB Output is correct
47 Correct 37 ms 83608 KB Output is correct
48 Correct 36 ms 83532 KB Output is correct
49 Correct 37 ms 83584 KB Output is correct
50 Correct 38 ms 83652 KB Output is correct
51 Correct 35 ms 83704 KB Output is correct
52 Correct 35 ms 83788 KB Output is correct
53 Correct 70 ms 84476 KB Output is correct
54 Correct 110 ms 85788 KB Output is correct
55 Correct 112 ms 86084 KB Output is correct
56 Correct 100 ms 85556 KB Output is correct
57 Correct 137 ms 86896 KB Output is correct
58 Correct 101 ms 84548 KB Output is correct
59 Correct 120 ms 85340 KB Output is correct