답안 #636561

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636561 2022-08-29T14:45:11 Z erto Toll (BOI17_toll) C++17
100 / 100
128 ms 86740 KB
#include <bits/stdc++.h>
typedef long long int ll;
#define INF (ll)(1e9 + 7)
#define INF2 998244353ll
#define N (ll)(1e5 + 5)
using namespace std;
//#define int ll
#define lsb(x) (x & (-x))

int n, m, k, g, h, o, t;
int dp[50001][17][5][5];
int temp[5][5], ans[5][5];

void comb(int res[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++){
                res[x][z] = min(res[x][z], a[x][y] + b[y][z]);
            }
        }
    }
}

void solve(){
    memset(dp, 0x3f, sizeof(dp));
    cin >> k >> n >> m >> o;
    for(int i=1; i<=m; i++){
        cin >> g >> h >> t;
        dp[g / k][0][g % k][h % k] = t;
    }

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

    for(int i=1; i<=o; i++){
        cin >> g >> h;
        memset(ans, 0x3f, sizeof(ans));
        for(int i=0; i<k; i++)ans[i][i] = 0;
        int fr = g / k, to = h / k;
        for(int i=16; ~i; i--){
            if(fr + (1 << i) <= to){
                memset(temp, 0x3f, sizeof(temp));
                comb(temp, ans, dp[fr][i]);
                fr += 1 << i;
                memcpy(ans, temp, sizeof(ans));
            }
        }
        if(ans[g % k][h % k] == 0x3f3f3f3f)cout << "-1\n";
        else{
            cout << ans[g % k][h % k] << '\n';
        }
    }
}   
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    //cin>>T;
    while (T--){
        solve();
    }
}

Compilation message

toll.cpp: In function 'void solve()':
toll.cpp:34:57: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   34 |             comb(dp[j][i], dp[j][i - 1], dp[j + (1 << i - 1)][i - 1]);
      |                                                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 84384 KB Output is correct
2 Correct 36 ms 83444 KB Output is correct
3 Correct 34 ms 83468 KB Output is correct
4 Correct 33 ms 83408 KB Output is correct
5 Correct 32 ms 83384 KB Output is correct
6 Correct 32 ms 83468 KB Output is correct
7 Correct 34 ms 83480 KB Output is correct
8 Correct 75 ms 84364 KB Output is correct
9 Correct 69 ms 84356 KB Output is correct
10 Correct 67 ms 83532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 85076 KB Output is correct
2 Correct 32 ms 83400 KB Output is correct
3 Correct 33 ms 83412 KB Output is correct
4 Correct 37 ms 83388 KB Output is correct
5 Correct 35 ms 83408 KB Output is correct
6 Correct 33 ms 83420 KB Output is correct
7 Correct 40 ms 83492 KB Output is correct
8 Correct 35 ms 83532 KB Output is correct
9 Correct 76 ms 84380 KB Output is correct
10 Correct 106 ms 85704 KB Output is correct
11 Correct 83 ms 85152 KB Output is correct
12 Correct 81 ms 84760 KB Output is correct
13 Correct 90 ms 85896 KB Output is correct
14 Correct 68 ms 84928 KB Output is correct
15 Correct 70 ms 84672 KB Output is correct
16 Correct 64 ms 84684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 83364 KB Output is correct
2 Correct 33 ms 83404 KB Output is correct
3 Correct 33 ms 83408 KB Output is correct
4 Correct 34 ms 83412 KB Output is correct
5 Correct 35 ms 83468 KB Output is correct
6 Correct 34 ms 83412 KB Output is correct
7 Correct 35 ms 83432 KB Output is correct
8 Correct 36 ms 83496 KB Output is correct
9 Correct 37 ms 83520 KB Output is correct
10 Correct 65 ms 84400 KB Output is correct
11 Correct 82 ms 85000 KB Output is correct
12 Correct 110 ms 85656 KB Output is correct
13 Correct 99 ms 85796 KB Output is correct
14 Correct 98 ms 85196 KB Output is correct
15 Correct 63 ms 84556 KB Output is correct
16 Correct 62 ms 84616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 83364 KB Output is correct
2 Correct 33 ms 83404 KB Output is correct
3 Correct 33 ms 83408 KB Output is correct
4 Correct 34 ms 83412 KB Output is correct
5 Correct 35 ms 83468 KB Output is correct
6 Correct 34 ms 83412 KB Output is correct
7 Correct 35 ms 83432 KB Output is correct
8 Correct 36 ms 83496 KB Output is correct
9 Correct 37 ms 83520 KB Output is correct
10 Correct 65 ms 84400 KB Output is correct
11 Correct 82 ms 85000 KB Output is correct
12 Correct 110 ms 85656 KB Output is correct
13 Correct 99 ms 85796 KB Output is correct
14 Correct 98 ms 85196 KB Output is correct
15 Correct 63 ms 84556 KB Output is correct
16 Correct 62 ms 84616 KB Output is correct
17 Correct 105 ms 85072 KB Output is correct
18 Correct 35 ms 83480 KB Output is correct
19 Correct 39 ms 83400 KB Output is correct
20 Correct 33 ms 83408 KB Output is correct
21 Correct 35 ms 83408 KB Output is correct
22 Correct 33 ms 83472 KB Output is correct
23 Correct 34 ms 83488 KB Output is correct
24 Correct 34 ms 83452 KB Output is correct
25 Correct 36 ms 83552 KB Output is correct
26 Correct 43 ms 83456 KB Output is correct
27 Correct 78 ms 84300 KB Output is correct
28 Correct 109 ms 85680 KB Output is correct
29 Correct 94 ms 85920 KB Output is correct
30 Correct 87 ms 85224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 84384 KB Output is correct
2 Correct 36 ms 83444 KB Output is correct
3 Correct 34 ms 83468 KB Output is correct
4 Correct 33 ms 83408 KB Output is correct
5 Correct 32 ms 83384 KB Output is correct
6 Correct 32 ms 83468 KB Output is correct
7 Correct 34 ms 83480 KB Output is correct
8 Correct 75 ms 84364 KB Output is correct
9 Correct 69 ms 84356 KB Output is correct
10 Correct 67 ms 83532 KB Output is correct
11 Correct 105 ms 85076 KB Output is correct
12 Correct 32 ms 83400 KB Output is correct
13 Correct 33 ms 83412 KB Output is correct
14 Correct 37 ms 83388 KB Output is correct
15 Correct 35 ms 83408 KB Output is correct
16 Correct 33 ms 83420 KB Output is correct
17 Correct 40 ms 83492 KB Output is correct
18 Correct 35 ms 83532 KB Output is correct
19 Correct 76 ms 84380 KB Output is correct
20 Correct 106 ms 85704 KB Output is correct
21 Correct 83 ms 85152 KB Output is correct
22 Correct 81 ms 84760 KB Output is correct
23 Correct 90 ms 85896 KB Output is correct
24 Correct 68 ms 84928 KB Output is correct
25 Correct 70 ms 84672 KB Output is correct
26 Correct 64 ms 84684 KB Output is correct
27 Correct 33 ms 83364 KB Output is correct
28 Correct 33 ms 83404 KB Output is correct
29 Correct 33 ms 83408 KB Output is correct
30 Correct 34 ms 83412 KB Output is correct
31 Correct 35 ms 83468 KB Output is correct
32 Correct 34 ms 83412 KB Output is correct
33 Correct 35 ms 83432 KB Output is correct
34 Correct 36 ms 83496 KB Output is correct
35 Correct 37 ms 83520 KB Output is correct
36 Correct 65 ms 84400 KB Output is correct
37 Correct 82 ms 85000 KB Output is correct
38 Correct 110 ms 85656 KB Output is correct
39 Correct 99 ms 85796 KB Output is correct
40 Correct 98 ms 85196 KB Output is correct
41 Correct 63 ms 84556 KB Output is correct
42 Correct 62 ms 84616 KB Output is correct
43 Correct 105 ms 85072 KB Output is correct
44 Correct 35 ms 83480 KB Output is correct
45 Correct 39 ms 83400 KB Output is correct
46 Correct 33 ms 83408 KB Output is correct
47 Correct 35 ms 83408 KB Output is correct
48 Correct 33 ms 83472 KB Output is correct
49 Correct 34 ms 83488 KB Output is correct
50 Correct 34 ms 83452 KB Output is correct
51 Correct 36 ms 83552 KB Output is correct
52 Correct 43 ms 83456 KB Output is correct
53 Correct 78 ms 84300 KB Output is correct
54 Correct 109 ms 85680 KB Output is correct
55 Correct 94 ms 85920 KB Output is correct
56 Correct 87 ms 85224 KB Output is correct
57 Correct 128 ms 86740 KB Output is correct
58 Correct 71 ms 84428 KB Output is correct
59 Correct 96 ms 85204 KB Output is correct