Submission #781363

# Submission time Handle Problem Language Result Execution time Memory
781363 2023-07-13T04:29:15 Z Cookie Toll (BOI17_toll) C++14
100 / 100
80 ms 79600 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 5e4 + 1, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5;
//const int base = (1 << 18);
const ll inf = 1e9 + 5, neg = -69420;

int k, n, m, o;
struct MAT{
    int a[5][5];
    void init(){
        for(int i = 0; i < k; i++){
            for(int j = 0; j < k; j++){
                a[i][j] = inf;
            }
        }
    }
    MAT operator *(const MAT &b){
        MAT res;
        for(int i = 0; i < k; i++){
            for(int j = 0; j < k; j++){
                res.a[i][j] = inf;
                for(int l = 0; l < k; l++){
                    res.a[i][j] = min(res.a[i][j], a[i][l] + b.a[l][j]);
                }
            }
        }
        return(res);
    }
};
MAT dp[mxn + 1][16];
void input(){
    cin >> k >> n >> m >> o;
    for(int i = 0; i <= (n - 1) / k; i++){
        for(int j = 0; j < 16; j++){
            dp[i][j].init();
        }
    }
    for(int i = 0; i < m; i++){
        int u, v, w; cin >> u >> v >> w;
        dp[u / k][0].a[u % k][v % k] = w;
    }

}
void process(){
    int mx = (n - 1) / k;
    for(int i = 1; i < 16; i++){
        for(int j = 0; j + (1 << i) - 1 <= mx; j++){
            dp[j][i] = dp[j][i - 1] * dp[j + (1 << (i - 1))][i - 1];
        }
    }
    
    for(int i = 0; i < o; i++){
        int u, v; cin >> u >> v;
        MAT ans; ans.init();
        forr(j, 0, k){
            ans.a[j][j] = 0;
        }
        int uu = (u / k), vv = (v / k);
        int dif = (vv - uu);
        for(int j = 0; j < 16; j++){
            if(dif & (1 << j)){
                ans = ans * dp[uu][j]; uu += (1 << j);
            }
        }
        cout << ((ans.a[u % k][v % k] == inf) ? -1 : ans.a[u % k][v % k]) << "\n";
    }
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    input();
    process();
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 80 ms 79600 KB Output is correct
2 Correct 1 ms 332 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 1876 KB Output is correct
6 Correct 2 ms 1876 KB Output is correct
7 Correct 2 ms 1876 KB Output is correct
8 Correct 77 ms 79476 KB Output is correct
9 Correct 75 ms 79476 KB Output is correct
10 Correct 60 ms 78716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 41060 KB Output is correct
2 Correct 0 ms 340 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 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 4 ms 1880 KB Output is correct
8 Correct 5 ms 1236 KB Output is correct
9 Correct 71 ms 79476 KB Output is correct
10 Correct 56 ms 28756 KB Output is correct
11 Correct 55 ms 41240 KB Output is correct
12 Correct 43 ms 27696 KB Output is correct
13 Correct 43 ms 12108 KB Output is correct
14 Correct 36 ms 17380 KB Output is correct
15 Correct 32 ms 10860 KB Output is correct
16 Correct 32 ms 10940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 212 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 1876 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 67 ms 79400 KB Output is correct
11 Correct 59 ms 41232 KB Output is correct
12 Correct 49 ms 28492 KB Output is correct
13 Correct 55 ms 28828 KB Output is correct
14 Correct 44 ms 28108 KB Output is correct
15 Correct 26 ms 10868 KB Output is correct
16 Correct 26 ms 10872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 212 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 1876 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 67 ms 79400 KB Output is correct
11 Correct 59 ms 41232 KB Output is correct
12 Correct 49 ms 28492 KB Output is correct
13 Correct 55 ms 28828 KB Output is correct
14 Correct 44 ms 28108 KB Output is correct
15 Correct 26 ms 10868 KB Output is correct
16 Correct 26 ms 10872 KB Output is correct
17 Correct 51 ms 41020 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 2 ms 1876 KB Output is correct
24 Correct 2 ms 1108 KB Output is correct
25 Correct 3 ms 728 KB Output is correct
26 Correct 2 ms 724 KB Output is correct
27 Correct 68 ms 79356 KB Output is correct
28 Correct 60 ms 28620 KB Output is correct
29 Correct 71 ms 28860 KB Output is correct
30 Correct 48 ms 28236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 79600 KB Output is correct
2 Correct 1 ms 332 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 1876 KB Output is correct
6 Correct 2 ms 1876 KB Output is correct
7 Correct 2 ms 1876 KB Output is correct
8 Correct 77 ms 79476 KB Output is correct
9 Correct 75 ms 79476 KB Output is correct
10 Correct 60 ms 78716 KB Output is correct
11 Correct 55 ms 41060 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 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 332 KB Output is correct
17 Correct 4 ms 1880 KB Output is correct
18 Correct 5 ms 1236 KB Output is correct
19 Correct 71 ms 79476 KB Output is correct
20 Correct 56 ms 28756 KB Output is correct
21 Correct 55 ms 41240 KB Output is correct
22 Correct 43 ms 27696 KB Output is correct
23 Correct 43 ms 12108 KB Output is correct
24 Correct 36 ms 17380 KB Output is correct
25 Correct 32 ms 10860 KB Output is correct
26 Correct 32 ms 10940 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 1876 KB Output is correct
33 Correct 1 ms 1108 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 1 ms 724 KB Output is correct
36 Correct 67 ms 79400 KB Output is correct
37 Correct 59 ms 41232 KB Output is correct
38 Correct 49 ms 28492 KB Output is correct
39 Correct 55 ms 28828 KB Output is correct
40 Correct 44 ms 28108 KB Output is correct
41 Correct 26 ms 10868 KB Output is correct
42 Correct 26 ms 10872 KB Output is correct
43 Correct 51 ms 41020 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 2 ms 1876 KB Output is correct
50 Correct 2 ms 1108 KB Output is correct
51 Correct 3 ms 728 KB Output is correct
52 Correct 2 ms 724 KB Output is correct
53 Correct 68 ms 79356 KB Output is correct
54 Correct 60 ms 28620 KB Output is correct
55 Correct 71 ms 28860 KB Output is correct
56 Correct 48 ms 28236 KB Output is correct
57 Correct 76 ms 23204 KB Output is correct
58 Correct 76 ms 79468 KB Output is correct
59 Correct 58 ms 41244 KB Output is correct