Submission #134255

# Submission time Handle Problem Language Result Execution time Memory
134255 2019-07-22T09:54:15 Z Kastanda Toll (BOI17_toll) C++11
100 / 100
169 ms 63632 KB
#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
using namespace std;
const int N = 150005, K = 6, LG = 17;
int n, m, k, q, P[LG][N][K];
int main()
{
	memset(P, 63, sizeof(P));
	scanf("%d%d%d%d", &k, &n, &m, &q);
	for (int i = 1; i <= m; i++)
	{
		int a, b, t;
		scanf("%d%d%d", &a, &b, &t);
		P[0][a][b % k] = min(P[0][a][b % k], t);
	}
	int pw = 1;
	for (int i = 1; i < LG; i++)
	{
		if (pw * k >= n)
			break;
		for (int j = 0; j < n; j++)
			for (int h = 0; h < k; h++)
				for (int md = 0; md < k; md++)
					P[i][j][h] = min(P[i][j][h], P[i - 1][j][md] + P[i - 1][(j / k + pw) * k + md][h]);
		pw <<= 1;
	}
	for (; q; q --)
	{
		int a, b, D[K], T[K];
		scanf("%d%d", &a, &b);
		if (a > b)
		{
			printf("-1\n");
			continue;
		}
		memset(D, 63, sizeof(D));
		D[a % k] = 0;
		a = a / k * k;
		for (int i = 0; i < LG; i++)
			if ((a / k - b / k) & (1 << i))
			{
				memset(T, 63, sizeof(T));
				for (int f = 0; f < k; f ++)
					for (int h = 0; h < k; h ++)
						T[h] = min(T[h], D[f] + P[i][a + f][h]);
				for (int h = 0; h < k; h ++)
					D[h] = T[h];
				a += (1 << i) * k;
			}
		if (D[b % k] > (int)(6e8))
			printf("-1\n");
		else
			printf("%d\n", D[b % k]);
	}
	return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &k, &n, &m, &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &t);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
toll.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 86 ms 61180 KB Output is correct
2 Correct 50 ms 60252 KB Output is correct
3 Correct 52 ms 60284 KB Output is correct
4 Correct 50 ms 60280 KB Output is correct
5 Correct 52 ms 60240 KB Output is correct
6 Correct 52 ms 60152 KB Output is correct
7 Correct 53 ms 60280 KB Output is correct
8 Correct 86 ms 61276 KB Output is correct
9 Correct 85 ms 61176 KB Output is correct
10 Correct 64 ms 60280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 61852 KB Output is correct
2 Correct 50 ms 60156 KB Output is correct
3 Correct 51 ms 60200 KB Output is correct
4 Correct 51 ms 60152 KB Output is correct
5 Correct 50 ms 60152 KB Output is correct
6 Correct 51 ms 60280 KB Output is correct
7 Correct 55 ms 60364 KB Output is correct
8 Correct 56 ms 60408 KB Output is correct
9 Correct 85 ms 61180 KB Output is correct
10 Correct 128 ms 62584 KB Output is correct
11 Correct 107 ms 61980 KB Output is correct
12 Correct 105 ms 61660 KB Output is correct
13 Correct 127 ms 62712 KB Output is correct
14 Correct 100 ms 61672 KB Output is correct
15 Correct 104 ms 61444 KB Output is correct
16 Correct 99 ms 61432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 60280 KB Output is correct
2 Correct 50 ms 60252 KB Output is correct
3 Correct 51 ms 60152 KB Output is correct
4 Correct 50 ms 60152 KB Output is correct
5 Correct 51 ms 60408 KB Output is correct
6 Correct 52 ms 60280 KB Output is correct
7 Correct 51 ms 60280 KB Output is correct
8 Correct 52 ms 60280 KB Output is correct
9 Correct 52 ms 60280 KB Output is correct
10 Correct 86 ms 61032 KB Output is correct
11 Correct 101 ms 61816 KB Output is correct
12 Correct 125 ms 62428 KB Output is correct
13 Correct 126 ms 62584 KB Output is correct
14 Correct 113 ms 62020 KB Output is correct
15 Correct 97 ms 61432 KB Output is correct
16 Correct 96 ms 61412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 60280 KB Output is correct
2 Correct 50 ms 60252 KB Output is correct
3 Correct 51 ms 60152 KB Output is correct
4 Correct 50 ms 60152 KB Output is correct
5 Correct 51 ms 60408 KB Output is correct
6 Correct 52 ms 60280 KB Output is correct
7 Correct 51 ms 60280 KB Output is correct
8 Correct 52 ms 60280 KB Output is correct
9 Correct 52 ms 60280 KB Output is correct
10 Correct 86 ms 61032 KB Output is correct
11 Correct 101 ms 61816 KB Output is correct
12 Correct 125 ms 62428 KB Output is correct
13 Correct 126 ms 62584 KB Output is correct
14 Correct 113 ms 62020 KB Output is correct
15 Correct 97 ms 61432 KB Output is correct
16 Correct 96 ms 61412 KB Output is correct
17 Correct 101 ms 61816 KB Output is correct
18 Correct 51 ms 60280 KB Output is correct
19 Correct 59 ms 60280 KB Output is correct
20 Correct 51 ms 60280 KB Output is correct
21 Correct 51 ms 60212 KB Output is correct
22 Correct 50 ms 60280 KB Output is correct
23 Correct 53 ms 60280 KB Output is correct
24 Correct 69 ms 60304 KB Output is correct
25 Correct 54 ms 60280 KB Output is correct
26 Correct 53 ms 60332 KB Output is correct
27 Correct 81 ms 61048 KB Output is correct
28 Correct 128 ms 62584 KB Output is correct
29 Correct 132 ms 62712 KB Output is correct
30 Correct 117 ms 62024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 61180 KB Output is correct
2 Correct 50 ms 60252 KB Output is correct
3 Correct 52 ms 60284 KB Output is correct
4 Correct 50 ms 60280 KB Output is correct
5 Correct 52 ms 60240 KB Output is correct
6 Correct 52 ms 60152 KB Output is correct
7 Correct 53 ms 60280 KB Output is correct
8 Correct 86 ms 61276 KB Output is correct
9 Correct 85 ms 61176 KB Output is correct
10 Correct 64 ms 60280 KB Output is correct
11 Correct 110 ms 61852 KB Output is correct
12 Correct 50 ms 60156 KB Output is correct
13 Correct 51 ms 60200 KB Output is correct
14 Correct 51 ms 60152 KB Output is correct
15 Correct 50 ms 60152 KB Output is correct
16 Correct 51 ms 60280 KB Output is correct
17 Correct 55 ms 60364 KB Output is correct
18 Correct 56 ms 60408 KB Output is correct
19 Correct 85 ms 61180 KB Output is correct
20 Correct 128 ms 62584 KB Output is correct
21 Correct 107 ms 61980 KB Output is correct
22 Correct 105 ms 61660 KB Output is correct
23 Correct 127 ms 62712 KB Output is correct
24 Correct 100 ms 61672 KB Output is correct
25 Correct 104 ms 61444 KB Output is correct
26 Correct 99 ms 61432 KB Output is correct
27 Correct 51 ms 60280 KB Output is correct
28 Correct 50 ms 60252 KB Output is correct
29 Correct 51 ms 60152 KB Output is correct
30 Correct 50 ms 60152 KB Output is correct
31 Correct 51 ms 60408 KB Output is correct
32 Correct 52 ms 60280 KB Output is correct
33 Correct 51 ms 60280 KB Output is correct
34 Correct 52 ms 60280 KB Output is correct
35 Correct 52 ms 60280 KB Output is correct
36 Correct 86 ms 61032 KB Output is correct
37 Correct 101 ms 61816 KB Output is correct
38 Correct 125 ms 62428 KB Output is correct
39 Correct 126 ms 62584 KB Output is correct
40 Correct 113 ms 62020 KB Output is correct
41 Correct 97 ms 61432 KB Output is correct
42 Correct 96 ms 61412 KB Output is correct
43 Correct 101 ms 61816 KB Output is correct
44 Correct 51 ms 60280 KB Output is correct
45 Correct 59 ms 60280 KB Output is correct
46 Correct 51 ms 60280 KB Output is correct
47 Correct 51 ms 60212 KB Output is correct
48 Correct 50 ms 60280 KB Output is correct
49 Correct 53 ms 60280 KB Output is correct
50 Correct 69 ms 60304 KB Output is correct
51 Correct 54 ms 60280 KB Output is correct
52 Correct 53 ms 60332 KB Output is correct
53 Correct 81 ms 61048 KB Output is correct
54 Correct 128 ms 62584 KB Output is correct
55 Correct 132 ms 62712 KB Output is correct
56 Correct 117 ms 62024 KB Output is correct
57 Correct 169 ms 63632 KB Output is correct
58 Correct 91 ms 61176 KB Output is correct
59 Correct 131 ms 61964 KB Output is correct