답안 #572698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572698 2022-06-05T05:51:17 Z 장태환(#8351) Toll (BOI17_toll) C++17
100 / 100
293 ms 209452 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[21][50100][5][5];
signed main()
{
	int K,N,M,O;
	cin >> K>>N>>M>>O;
	int i;
	memset(dp, 1, sizeof(dp));
	for (i = 0; i < M; i++)
	{
		int a, b,c;
		cin >> a >> b>>c;
		dp[0][a / K][a % K][b % K] = c;
	}
	for (i = 0; i < 20; i++)
	{
		int j;
		for (j = 0; j <=N/K+2; j++)
		{
			int ne = j + (1 << i);
			if (ne > N / K + 2)
				break;
			int k, l, m;
			for (k = 0; k < 5; k++)
			{
				for (l = 0; l < 5; l++)
				{
					for (m = 0; m < 5; m++)
					{
						dp[i + 1][j][k][l] = min(dp[i + 1][j][k][l], dp[i][j][k][m] + dp[i][ne][m][l]);
					}
				}
			}
		}
	}
	while (O--)
	{
		int x, y;
		cin >> x >> y;
		int sp = x % K;
		int ep = y % K;
		x /= K;
		y /= K;
		if (x == y)
		{
			cout << -1 << '\n';
			continue;
		}
		int cd[5][5];
		memset(cd, 1, sizeof(cd));
		for (i = 0; i < 5; i++)
			cd[i][i] = 0;
		for (i = 20; i >= 0; i--)
		{
			int ne = x + (1 << i);
			if (ne <= y)
			{
				int ncd[5][5];
				memset(ncd, 1, sizeof(ncd));
				int k, l, m;
				for (k = 0; k < 5; k++)
				{
					for (l = 0; l < 5; l++)
					{
						for (m = 0; m < 5; m++)
						{
							ncd[k][l] = min(ncd[k][l], dp[i][x][m][l] + cd[k][m]);
						}
					}
				}
				for (k = 0; k < 5; k++)
				{
					for (l = 0; l < 5; l++)
					{
						cd[k][l] = ncd[k][l];
					}
				}
				x = ne;
			}
		}
		if (cd[sp][ep] >= (1LL << 30))
			cout << -1 << '\n';
		else
			cout << cd[sp][ep] << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 207312 KB Output is correct
2 Correct 79 ms 206056 KB Output is correct
3 Correct 76 ms 206056 KB Output is correct
4 Correct 77 ms 206120 KB Output is correct
5 Correct 88 ms 206184 KB Output is correct
6 Correct 79 ms 206148 KB Output is correct
7 Correct 78 ms 206172 KB Output is correct
8 Correct 246 ms 207040 KB Output is correct
9 Correct 254 ms 207052 KB Output is correct
10 Correct 209 ms 206316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 231 ms 207820 KB Output is correct
2 Correct 76 ms 206164 KB Output is correct
3 Correct 75 ms 206124 KB Output is correct
4 Correct 74 ms 206116 KB Output is correct
5 Correct 78 ms 206052 KB Output is correct
6 Correct 86 ms 206136 KB Output is correct
7 Correct 106 ms 206212 KB Output is correct
8 Correct 104 ms 206272 KB Output is correct
9 Correct 240 ms 207052 KB Output is correct
10 Correct 249 ms 208400 KB Output is correct
11 Correct 224 ms 207944 KB Output is correct
12 Correct 198 ms 207564 KB Output is correct
13 Correct 201 ms 208464 KB Output is correct
14 Correct 227 ms 207616 KB Output is correct
15 Correct 176 ms 207308 KB Output is correct
16 Correct 157 ms 207360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 206124 KB Output is correct
2 Correct 84 ms 206176 KB Output is correct
3 Correct 75 ms 206108 KB Output is correct
4 Correct 87 ms 206088 KB Output is correct
5 Correct 92 ms 206184 KB Output is correct
6 Correct 77 ms 206124 KB Output is correct
7 Correct 79 ms 206124 KB Output is correct
8 Correct 79 ms 206200 KB Output is correct
9 Correct 84 ms 206196 KB Output is correct
10 Correct 222 ms 207100 KB Output is correct
11 Correct 191 ms 207644 KB Output is correct
12 Correct 198 ms 208228 KB Output is correct
13 Correct 216 ms 208584 KB Output is correct
14 Correct 192 ms 207948 KB Output is correct
15 Correct 138 ms 207248 KB Output is correct
16 Correct 151 ms 207304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 206124 KB Output is correct
2 Correct 84 ms 206176 KB Output is correct
3 Correct 75 ms 206108 KB Output is correct
4 Correct 87 ms 206088 KB Output is correct
5 Correct 92 ms 206184 KB Output is correct
6 Correct 77 ms 206124 KB Output is correct
7 Correct 79 ms 206124 KB Output is correct
8 Correct 79 ms 206200 KB Output is correct
9 Correct 84 ms 206196 KB Output is correct
10 Correct 222 ms 207100 KB Output is correct
11 Correct 191 ms 207644 KB Output is correct
12 Correct 198 ms 208228 KB Output is correct
13 Correct 216 ms 208584 KB Output is correct
14 Correct 192 ms 207948 KB Output is correct
15 Correct 138 ms 207248 KB Output is correct
16 Correct 151 ms 207304 KB Output is correct
17 Correct 223 ms 207704 KB Output is correct
18 Correct 75 ms 206152 KB Output is correct
19 Correct 77 ms 206172 KB Output is correct
20 Correct 79 ms 206076 KB Output is correct
21 Correct 77 ms 206064 KB Output is correct
22 Correct 80 ms 206068 KB Output is correct
23 Correct 91 ms 206320 KB Output is correct
24 Correct 85 ms 206156 KB Output is correct
25 Correct 98 ms 206256 KB Output is correct
26 Correct 87 ms 206208 KB Output is correct
27 Correct 237 ms 207016 KB Output is correct
28 Correct 214 ms 208324 KB Output is correct
29 Correct 223 ms 208596 KB Output is correct
30 Correct 219 ms 207948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 262 ms 207312 KB Output is correct
2 Correct 79 ms 206056 KB Output is correct
3 Correct 76 ms 206056 KB Output is correct
4 Correct 77 ms 206120 KB Output is correct
5 Correct 88 ms 206184 KB Output is correct
6 Correct 79 ms 206148 KB Output is correct
7 Correct 78 ms 206172 KB Output is correct
8 Correct 246 ms 207040 KB Output is correct
9 Correct 254 ms 207052 KB Output is correct
10 Correct 209 ms 206316 KB Output is correct
11 Correct 231 ms 207820 KB Output is correct
12 Correct 76 ms 206164 KB Output is correct
13 Correct 75 ms 206124 KB Output is correct
14 Correct 74 ms 206116 KB Output is correct
15 Correct 78 ms 206052 KB Output is correct
16 Correct 86 ms 206136 KB Output is correct
17 Correct 106 ms 206212 KB Output is correct
18 Correct 104 ms 206272 KB Output is correct
19 Correct 240 ms 207052 KB Output is correct
20 Correct 249 ms 208400 KB Output is correct
21 Correct 224 ms 207944 KB Output is correct
22 Correct 198 ms 207564 KB Output is correct
23 Correct 201 ms 208464 KB Output is correct
24 Correct 227 ms 207616 KB Output is correct
25 Correct 176 ms 207308 KB Output is correct
26 Correct 157 ms 207360 KB Output is correct
27 Correct 86 ms 206124 KB Output is correct
28 Correct 84 ms 206176 KB Output is correct
29 Correct 75 ms 206108 KB Output is correct
30 Correct 87 ms 206088 KB Output is correct
31 Correct 92 ms 206184 KB Output is correct
32 Correct 77 ms 206124 KB Output is correct
33 Correct 79 ms 206124 KB Output is correct
34 Correct 79 ms 206200 KB Output is correct
35 Correct 84 ms 206196 KB Output is correct
36 Correct 222 ms 207100 KB Output is correct
37 Correct 191 ms 207644 KB Output is correct
38 Correct 198 ms 208228 KB Output is correct
39 Correct 216 ms 208584 KB Output is correct
40 Correct 192 ms 207948 KB Output is correct
41 Correct 138 ms 207248 KB Output is correct
42 Correct 151 ms 207304 KB Output is correct
43 Correct 223 ms 207704 KB Output is correct
44 Correct 75 ms 206152 KB Output is correct
45 Correct 77 ms 206172 KB Output is correct
46 Correct 79 ms 206076 KB Output is correct
47 Correct 77 ms 206064 KB Output is correct
48 Correct 80 ms 206068 KB Output is correct
49 Correct 91 ms 206320 KB Output is correct
50 Correct 85 ms 206156 KB Output is correct
51 Correct 98 ms 206256 KB Output is correct
52 Correct 87 ms 206208 KB Output is correct
53 Correct 237 ms 207016 KB Output is correct
54 Correct 214 ms 208324 KB Output is correct
55 Correct 223 ms 208596 KB Output is correct
56 Correct 219 ms 207948 KB Output is correct
57 Correct 293 ms 209452 KB Output is correct
58 Correct 254 ms 207172 KB Output is correct
59 Correct 240 ms 207892 KB Output is correct