답안 #857339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
857339 2023-10-05T23:48:51 Z NK_ Toll (BOI17_toll) C++17
100 / 100
173 ms 93764 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
 
using namespace std;
 
#define nl '\n'
#define pb push_back
#define pf push_front
 
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
 
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
 
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
 
using db = long double;
 
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
 
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
const int LG = 18;

using T = array<array<int, 5>, 5>;

const T FUL = {
	array<int, 5>{MOD, MOD, MOD, MOD, MOD},
	array<int, 5>{MOD, MOD, MOD, MOD, MOD},
	array<int, 5>{MOD, MOD, MOD, MOD, MOD},
	array<int, 5>{MOD, MOD, MOD, MOD, MOD},
	array<int, 5>{MOD, MOD, MOD, MOD, MOD}
};

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int N, M, Q, K; cin >> K >> N >> M >> Q;
	int LVL = (N + K - 1) / K;

	V<vpi> nxt(N);
	for(int i = 0; i < M; i++) {
		int a, b, t; cin >> a >> b >> t;
		nxt[a].pb(mp(b, t));
	}

	V<V<T>> up(LVL, V<T>(LG, FUL));

	for(int i = 0; i < N; i++) {
		int blk = i / K, x = i % K;

		for(auto e : nxt[i]) {
			int v, w; tie(v, w) = e;
			up[blk][0][x][v % K] = min(up[blk][0][x][v % K], w);
		}

	}
	for(int blk = LVL - 1; blk >= 0; blk--) {
		for(int d = 1; d < LG; d++) if ((blk + (1 << (d - 1))) < LVL) {
			for(int a = 0; a < 5; a++) for(int b = 0; b < 5; b++) for(int c = 0; c < 5; c++) {
				up[blk][d][a][c] = min(up[blk][d][a][c], up[blk][d-1][a][b] + up[blk + (1 << (d - 1))][d-1][b][c]);
			}
		}
	}

	for(int i = 0; i < Q; i++) {
		int u, v; cin >> u >> v;

		// cout << u << " - " << v << endl;
		int bu = u / K, bv = v / K;
		u %= K, v %= K;

		array<int, 5> ans = {MOD, MOD, MOD, MOD, MOD}; ans[u] = 0;
		// cout << bu << " = " << bv << endl;
		for(int b = bu, d = LG - 1; d >= 0; d--) {
			if ((b + (1 << d)) <= bv) {
				// cout << b << " " << d << endl;

				array<int, 5> nans = {MOD, MOD, MOD, MOD, MOD};

				for(int x = 0; x < 5; x++) for(int y = 0; y < 5; y++) {
					nans[y] = min(ans[x] + up[b][d][x][y], nans[y]);
				}

				b += (1 << d);
				ans.swap(nans);
			}
		} 

		cout << (ans[v] == MOD ? -1 : ans[v]) << nl;
		// cout << endl;
	}


	exit(0-0);
} 	 
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 92764 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 2140 KB Output is correct
6 Correct 3 ms 2140 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 166 ms 93764 KB Output is correct
9 Correct 165 ms 93524 KB Output is correct
10 Correct 161 ms 91256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 47956 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 7 ms 2396 KB Output is correct
8 Correct 5 ms 1372 KB Output is correct
9 Correct 173 ms 93692 KB Output is correct
10 Correct 77 ms 36556 KB Output is correct
11 Correct 94 ms 49692 KB Output is correct
12 Correct 65 ms 34248 KB Output is correct
13 Correct 48 ms 16916 KB Output is correct
14 Correct 45 ms 22220 KB Output is correct
15 Correct 31 ms 14420 KB Output is correct
16 Correct 31 ms 14424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 2256 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 172 ms 93444 KB Output is correct
11 Correct 87 ms 49316 KB Output is correct
12 Correct 84 ms 35920 KB Output is correct
13 Correct 75 ms 36536 KB Output is correct
14 Correct 66 ms 35384 KB Output is correct
15 Correct 30 ms 14168 KB Output is correct
16 Correct 30 ms 14164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 2256 KB Output is correct
7 Correct 2 ms 1372 KB Output is correct
8 Correct 2 ms 860 KB Output is correct
9 Correct 1 ms 856 KB Output is correct
10 Correct 172 ms 93444 KB Output is correct
11 Correct 87 ms 49316 KB Output is correct
12 Correct 84 ms 35920 KB Output is correct
13 Correct 75 ms 36536 KB Output is correct
14 Correct 66 ms 35384 KB Output is correct
15 Correct 30 ms 14168 KB Output is correct
16 Correct 30 ms 14164 KB Output is correct
17 Correct 89 ms 49556 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 3 ms 2140 KB Output is correct
24 Correct 3 ms 1372 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 4 ms 860 KB Output is correct
27 Correct 156 ms 93652 KB Output is correct
28 Correct 75 ms 36180 KB Output is correct
29 Correct 93 ms 36940 KB Output is correct
30 Correct 69 ms 35428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 92764 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 3 ms 2140 KB Output is correct
6 Correct 3 ms 2140 KB Output is correct
7 Correct 3 ms 2140 KB Output is correct
8 Correct 166 ms 93764 KB Output is correct
9 Correct 165 ms 93524 KB Output is correct
10 Correct 161 ms 91256 KB Output is correct
11 Correct 106 ms 47956 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 452 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 7 ms 2396 KB Output is correct
18 Correct 5 ms 1372 KB Output is correct
19 Correct 173 ms 93692 KB Output is correct
20 Correct 77 ms 36556 KB Output is correct
21 Correct 94 ms 49692 KB Output is correct
22 Correct 65 ms 34248 KB Output is correct
23 Correct 48 ms 16916 KB Output is correct
24 Correct 45 ms 22220 KB Output is correct
25 Correct 31 ms 14420 KB Output is correct
26 Correct 31 ms 14424 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 2 ms 2256 KB Output is correct
33 Correct 2 ms 1372 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 1 ms 856 KB Output is correct
36 Correct 172 ms 93444 KB Output is correct
37 Correct 87 ms 49316 KB Output is correct
38 Correct 84 ms 35920 KB Output is correct
39 Correct 75 ms 36536 KB Output is correct
40 Correct 66 ms 35384 KB Output is correct
41 Correct 30 ms 14168 KB Output is correct
42 Correct 30 ms 14164 KB Output is correct
43 Correct 89 ms 49556 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 600 KB Output is correct
49 Correct 3 ms 2140 KB Output is correct
50 Correct 3 ms 1372 KB Output is correct
51 Correct 2 ms 860 KB Output is correct
52 Correct 4 ms 860 KB Output is correct
53 Correct 156 ms 93652 KB Output is correct
54 Correct 75 ms 36180 KB Output is correct
55 Correct 93 ms 36940 KB Output is correct
56 Correct 69 ms 35428 KB Output is correct
57 Correct 82 ms 29996 KB Output is correct
58 Correct 165 ms 93524 KB Output is correct
59 Correct 104 ms 49744 KB Output is correct