답안 #646651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646651 2022-09-30T11:23:32 Z mychecksedad Toll (BOI17_toll) C++17
100 / 100
147 ms 42756 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 50000+10, F = 2147483646, K = 20;




int k, n, m, q;
ll dp[M][K][5];

void solve(){
    cin >> k >> n >> m >> q;
   
    for(int i = 0; i <= n + k; ++i){
        for(int j = 0; j < K; ++j){
            for(int l = 0; l < k; ++l)
                dp[i][j][l] = 1e18;
        }
    }


    for(int i = 0; i < m; ++i){
        int u, v, e; cin >> u >> v >> e;
        dp[u][0][v % k] = min(dp[u][0][v % k], 1ll * e);
    }
    for(int j = 1; j < K; ++j){
        for(int i = 0; i < n; ++i){
            for(int l = 0; l < k; ++l){
                for(int p = 0; p < k; ++p){
                    int d = (1<<(j-1)) * k;
                    if((i/k*k) + d + p < n){
                        dp[i][j][l] = min(dp[i][j][l], dp[i][j - 1][p] + dp[(i/k*k) + d + p][j - 1][l]); 
                    }
                }
            }
        }
    }
    for(;q--;){
        int a, b; cin >> a >> b;
        int dep = b/k - a/k;

        vector<ll> dist (k, ll(1e18));
        dist[a % k] = 0;

        int cur = a/k*k;

        for(int j = K - 1; j >= 0; --j){
            if((1<<j)&dep){
                vector<ll> t (k, ll(1e18));
                for(int l = 0; l < k; ++l){
                    for(int p = 0; p < k; ++p){
                        int d = (1<<j) * k;
                        t[l % k] = min(t[l % k], dist[p] + dp[cur + p][j][l]); 
                    }
                }
                cur += (1<<j)*k;

                dist = t;
            }
        }

        if(dist[b % k] == 1e18) cout << -1;
        else cout << dist[b % k];
        cout << '\n';
    }
}





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
}

Compilation message

toll.cpp: In function 'void solve()':
toll.cpp:65:29: warning: unused variable 'd' [-Wunused-variable]
   65 |                         int d = (1<<j) * k;
      |                             ^
toll.cpp: In function 'int main()':
toll.cpp:87:16: warning: unused variable 'aa' [-Wunused-variable]
   87 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 40456 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 2 ms 1108 KB Output is correct
7 Correct 2 ms 1136 KB Output is correct
8 Correct 53 ms 40324 KB Output is correct
9 Correct 51 ms 40360 KB Output is correct
10 Correct 37 ms 39520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 40996 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 6 ms 1108 KB Output is correct
8 Correct 6 ms 1244 KB Output is correct
9 Correct 49 ms 40328 KB Output is correct
10 Correct 98 ms 41736 KB Output is correct
11 Correct 82 ms 41164 KB Output is correct
12 Correct 95 ms 40864 KB Output is correct
13 Correct 89 ms 26188 KB Output is correct
14 Correct 52 ms 25208 KB Output is correct
15 Correct 71 ms 25008 KB Output is correct
16 Correct 77 ms 24908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1148 KB Output is correct
8 Correct 2 ms 1108 KB Output is correct
9 Correct 2 ms 1108 KB Output is correct
10 Correct 44 ms 40248 KB Output is correct
11 Correct 68 ms 40964 KB Output is correct
12 Correct 101 ms 41540 KB Output is correct
13 Correct 101 ms 41872 KB Output is correct
14 Correct 88 ms 41236 KB Output is correct
15 Correct 69 ms 24984 KB Output is correct
16 Correct 78 ms 24948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1148 KB Output is correct
8 Correct 2 ms 1108 KB Output is correct
9 Correct 2 ms 1108 KB Output is correct
10 Correct 44 ms 40248 KB Output is correct
11 Correct 68 ms 40964 KB Output is correct
12 Correct 101 ms 41540 KB Output is correct
13 Correct 101 ms 41872 KB Output is correct
14 Correct 88 ms 41236 KB Output is correct
15 Correct 69 ms 24984 KB Output is correct
16 Correct 78 ms 24948 KB Output is correct
17 Correct 69 ms 40980 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 1108 KB Output is correct
24 Correct 3 ms 1168 KB Output is correct
25 Correct 4 ms 1108 KB Output is correct
26 Correct 3 ms 1108 KB Output is correct
27 Correct 46 ms 40208 KB Output is correct
28 Correct 95 ms 41604 KB Output is correct
29 Correct 101 ms 41832 KB Output is correct
30 Correct 95 ms 41348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 40456 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 2 ms 1108 KB Output is correct
7 Correct 2 ms 1136 KB Output is correct
8 Correct 53 ms 40324 KB Output is correct
9 Correct 51 ms 40360 KB Output is correct
10 Correct 37 ms 39520 KB Output is correct
11 Correct 78 ms 40996 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 6 ms 1108 KB Output is correct
18 Correct 6 ms 1244 KB Output is correct
19 Correct 49 ms 40328 KB Output is correct
20 Correct 98 ms 41736 KB Output is correct
21 Correct 82 ms 41164 KB Output is correct
22 Correct 95 ms 40864 KB Output is correct
23 Correct 89 ms 26188 KB Output is correct
24 Correct 52 ms 25208 KB Output is correct
25 Correct 71 ms 25008 KB Output is correct
26 Correct 77 ms 24908 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 1108 KB Output is correct
33 Correct 1 ms 1148 KB Output is correct
34 Correct 2 ms 1108 KB Output is correct
35 Correct 2 ms 1108 KB Output is correct
36 Correct 44 ms 40248 KB Output is correct
37 Correct 68 ms 40964 KB Output is correct
38 Correct 101 ms 41540 KB Output is correct
39 Correct 101 ms 41872 KB Output is correct
40 Correct 88 ms 41236 KB Output is correct
41 Correct 69 ms 24984 KB Output is correct
42 Correct 78 ms 24948 KB Output is correct
43 Correct 69 ms 40980 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 1 ms 328 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 2 ms 1108 KB Output is correct
50 Correct 3 ms 1168 KB Output is correct
51 Correct 4 ms 1108 KB Output is correct
52 Correct 3 ms 1108 KB Output is correct
53 Correct 46 ms 40208 KB Output is correct
54 Correct 95 ms 41604 KB Output is correct
55 Correct 101 ms 41832 KB Output is correct
56 Correct 95 ms 41348 KB Output is correct
57 Correct 147 ms 42756 KB Output is correct
58 Correct 53 ms 40368 KB Output is correct
59 Correct 108 ms 41220 KB Output is correct