Submission #696782

# Submission time Handle Problem Language Result Execution time Memory
696782 2023-02-07T08:57:10 Z vjudge1 Toll (BOI17_toll) C++17
100 / 100
421 ms 176588 KB
// #pragma gcc optimize("Ofast")
// #pragma GCC optimization("Ofast")
// #pragma optimize(Ofast)
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

/**
 *    author:  tpa1410 - futorankusu
 *    rose, hanni, minji     
**/

#include<bits/stdc++.h>

using namespace std;

#define ll long long
typedef pair<ll, ll> pii;
#define rose() ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gcd __gcd
#define getl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
#define mset(a) memset(a, 0, sizeof(a))
#define endl '\n'



const ll hanni = 1e4, minji = 1e9;

struct Matrix{
	long long int a[5][5];
	Matrix(){
		for(int i = 0; i < 5; i++){
			for (int j = 0; j < 5; j++){
				a[i][j] = minji;
			}
		}
	}
};

Matrix mul(Matrix a, Matrix b){
    Matrix c;
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            c.a[i][j] = minji;
            for (int k = 0; k < 5; k++) {
                c.a[i][j] = min(c.a[i][j], a.a[i][k] + b.a[k][j]);
            }
        }
    }
    return c;
}

Matrix up[50005][18];
signed main(){
	int k, n, m, o;
    cin >> k >> n >> m >> o;
    for(int i=1; i<=m; i++) {
    	int u, v, w;
    	cin >> u >> v >> w;
//     	up[j][i]: tầng thứ 2^i bên cạnh tầng j
    	up[u/k][0].a[u%k][v%k] = w;
//     	a[x][y]: x là vị trí của đỉnh u trong tầng u nằm, y tương tự là của v
    }
    for(int i=1; (1 << i) <= n; i++){
    	for(int j=0; j + (1 << i) - 1 <= n; j++){
    		up[j][i] = mul(up[j][i-1], up[j+(1<<(i-1))][i-1]);
    	}
    }
    for(int i = 0; i<o; i++){
    	int a, b;
    	cin >> a >> b;
    	Matrix res;
    	for(int j = 0; j < 5; j++){
    		res.a[j][j] = 0;
    	}
    	if(a == b){
    		cout << 0 << endl;
    		continue;
    	}
    	int div1 = a / k, div2 = b / k;
    	int dist = div2 - div1;
    	for(int j = 16; j >= 0; j--){
    		if(dist & (1 << j)){
    			res = mul(res, up[div1][j]);
    			div1 += (1 << j);
    		}
    	}
    	if(res.a[a % k][b % k] == minji) cout << -1 << endl;
    	else cout << res.a[a % k][b % k] << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 305 ms 176420 KB Output is correct
2 Correct 70 ms 176388 KB Output is correct
3 Correct 72 ms 176460 KB Output is correct
4 Correct 70 ms 176408 KB Output is correct
5 Correct 87 ms 176332 KB Output is correct
6 Correct 76 ms 176380 KB Output is correct
7 Correct 74 ms 176404 KB Output is correct
8 Correct 313 ms 176428 KB Output is correct
9 Correct 302 ms 176424 KB Output is correct
10 Correct 266 ms 176420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 339 ms 176588 KB Output is correct
2 Correct 69 ms 176356 KB Output is correct
3 Correct 70 ms 176332 KB Output is correct
4 Correct 74 ms 176428 KB Output is correct
5 Correct 70 ms 176376 KB Output is correct
6 Correct 72 ms 176304 KB Output is correct
7 Correct 100 ms 176408 KB Output is correct
8 Correct 97 ms 176444 KB Output is correct
9 Correct 310 ms 176416 KB Output is correct
10 Correct 364 ms 176448 KB Output is correct
11 Correct 332 ms 176420 KB Output is correct
12 Correct 318 ms 176336 KB Output is correct
13 Correct 266 ms 176328 KB Output is correct
14 Correct 232 ms 176420 KB Output is correct
15 Correct 237 ms 176416 KB Output is correct
16 Correct 226 ms 176516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 176428 KB Output is correct
2 Correct 81 ms 176392 KB Output is correct
3 Correct 75 ms 176364 KB Output is correct
4 Correct 68 ms 176368 KB Output is correct
5 Correct 69 ms 176344 KB Output is correct
6 Correct 87 ms 176428 KB Output is correct
7 Correct 76 ms 176420 KB Output is correct
8 Correct 76 ms 176332 KB Output is correct
9 Correct 73 ms 176376 KB Output is correct
10 Correct 258 ms 176420 KB Output is correct
11 Correct 301 ms 176464 KB Output is correct
12 Correct 335 ms 176424 KB Output is correct
13 Correct 364 ms 176452 KB Output is correct
14 Correct 328 ms 176348 KB Output is correct
15 Correct 233 ms 176416 KB Output is correct
16 Correct 205 ms 176420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 176428 KB Output is correct
2 Correct 81 ms 176392 KB Output is correct
3 Correct 75 ms 176364 KB Output is correct
4 Correct 68 ms 176368 KB Output is correct
5 Correct 69 ms 176344 KB Output is correct
6 Correct 87 ms 176428 KB Output is correct
7 Correct 76 ms 176420 KB Output is correct
8 Correct 76 ms 176332 KB Output is correct
9 Correct 73 ms 176376 KB Output is correct
10 Correct 258 ms 176420 KB Output is correct
11 Correct 301 ms 176464 KB Output is correct
12 Correct 335 ms 176424 KB Output is correct
13 Correct 364 ms 176452 KB Output is correct
14 Correct 328 ms 176348 KB Output is correct
15 Correct 233 ms 176416 KB Output is correct
16 Correct 205 ms 176420 KB Output is correct
17 Correct 307 ms 176332 KB Output is correct
18 Correct 75 ms 176332 KB Output is correct
19 Correct 77 ms 176344 KB Output is correct
20 Correct 77 ms 176336 KB Output is correct
21 Correct 70 ms 176324 KB Output is correct
22 Correct 71 ms 176388 KB Output is correct
23 Correct 83 ms 176336 KB Output is correct
24 Correct 86 ms 176504 KB Output is correct
25 Correct 80 ms 176332 KB Output is correct
26 Correct 90 ms 176440 KB Output is correct
27 Correct 281 ms 176424 KB Output is correct
28 Correct 343 ms 176432 KB Output is correct
29 Correct 385 ms 176420 KB Output is correct
30 Correct 328 ms 176420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 305 ms 176420 KB Output is correct
2 Correct 70 ms 176388 KB Output is correct
3 Correct 72 ms 176460 KB Output is correct
4 Correct 70 ms 176408 KB Output is correct
5 Correct 87 ms 176332 KB Output is correct
6 Correct 76 ms 176380 KB Output is correct
7 Correct 74 ms 176404 KB Output is correct
8 Correct 313 ms 176428 KB Output is correct
9 Correct 302 ms 176424 KB Output is correct
10 Correct 266 ms 176420 KB Output is correct
11 Correct 339 ms 176588 KB Output is correct
12 Correct 69 ms 176356 KB Output is correct
13 Correct 70 ms 176332 KB Output is correct
14 Correct 74 ms 176428 KB Output is correct
15 Correct 70 ms 176376 KB Output is correct
16 Correct 72 ms 176304 KB Output is correct
17 Correct 100 ms 176408 KB Output is correct
18 Correct 97 ms 176444 KB Output is correct
19 Correct 310 ms 176416 KB Output is correct
20 Correct 364 ms 176448 KB Output is correct
21 Correct 332 ms 176420 KB Output is correct
22 Correct 318 ms 176336 KB Output is correct
23 Correct 266 ms 176328 KB Output is correct
24 Correct 232 ms 176420 KB Output is correct
25 Correct 237 ms 176416 KB Output is correct
26 Correct 226 ms 176516 KB Output is correct
27 Correct 68 ms 176428 KB Output is correct
28 Correct 81 ms 176392 KB Output is correct
29 Correct 75 ms 176364 KB Output is correct
30 Correct 68 ms 176368 KB Output is correct
31 Correct 69 ms 176344 KB Output is correct
32 Correct 87 ms 176428 KB Output is correct
33 Correct 76 ms 176420 KB Output is correct
34 Correct 76 ms 176332 KB Output is correct
35 Correct 73 ms 176376 KB Output is correct
36 Correct 258 ms 176420 KB Output is correct
37 Correct 301 ms 176464 KB Output is correct
38 Correct 335 ms 176424 KB Output is correct
39 Correct 364 ms 176452 KB Output is correct
40 Correct 328 ms 176348 KB Output is correct
41 Correct 233 ms 176416 KB Output is correct
42 Correct 205 ms 176420 KB Output is correct
43 Correct 307 ms 176332 KB Output is correct
44 Correct 75 ms 176332 KB Output is correct
45 Correct 77 ms 176344 KB Output is correct
46 Correct 77 ms 176336 KB Output is correct
47 Correct 70 ms 176324 KB Output is correct
48 Correct 71 ms 176388 KB Output is correct
49 Correct 83 ms 176336 KB Output is correct
50 Correct 86 ms 176504 KB Output is correct
51 Correct 80 ms 176332 KB Output is correct
52 Correct 90 ms 176440 KB Output is correct
53 Correct 281 ms 176424 KB Output is correct
54 Correct 343 ms 176432 KB Output is correct
55 Correct 385 ms 176420 KB Output is correct
56 Correct 328 ms 176420 KB Output is correct
57 Correct 421 ms 176380 KB Output is correct
58 Correct 342 ms 176444 KB Output is correct
59 Correct 349 ms 176412 KB Output is correct