Submission #380452

# Submission time Handle Problem Language Result Execution time Memory
380452 2021-03-22T00:50:49 Z LittlePants Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
736 ms 112572 KB
#include <queue>
#include <tuple>
#include <bitset>
#include <cstdio>
#include <vector>
#include <algorithm>

const int maxN = 30005;

int N, M, S, T;
std::vector<int> Doge[maxN];
std::queue<std::tuple<int, int, int>> Q;
std::bitset<maxN> vis[maxN];
bool Vis[maxN];

void insert(int i, int p, int step)
{
	if (!Vis[i])
	{
		Vis[i] = true;
		for (auto x : Doge[i])
			if (!vis[i].test(x))
				vis[i].set(x), Q.emplace(i, x, step);
	}
	if (!vis[i].test(p))
		vis[i].set(p), Q.emplace(i, p, step);
}

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0, b, p; i != M; ++i)
	{
		scanf("%d%d", &b, &p);
		if (i == 0)
			S = b;
		if (i == 1)
			T = b;
		Doge[b].push_back(p);
	}

	if (S == T)
	{
		puts("0");
		return 0;
	}

	Vis[S] = true;
	for (auto x : Doge[S])
		if (!vis[S].test(x))
		{
			vis[S].set(x);
			Q.emplace(S, x, 0);
		}

	while (!Q.empty())
	{
		int i, p, step;
		std::tie(i, p, step) = Q.front();
		Q.pop();
		if (i - p == T || i + p == T)
		{
			printf("%d\n", step + 1);
			return 0;
		}
		if (i - p >= 0)
			insert(i - p, p, step + 1);
		if (i + p < N)
			insert(i + p, p, step + 1);
	}

	puts("-1");

	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |   scanf("%d%d", &b, &p);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1024 KB Output is correct
6 Correct 1 ms 1024 KB Output is correct
7 Correct 2 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 2 ms 1388 KB Output is correct
13 Correct 1 ms 1388 KB Output is correct
14 Correct 2 ms 1388 KB Output is correct
15 Correct 2 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1152 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 1 ms 1388 KB Output is correct
13 Correct 1 ms 1388 KB Output is correct
14 Correct 2 ms 1388 KB Output is correct
15 Correct 2 ms 1388 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 3 ms 3436 KB Output is correct
18 Correct 1 ms 1004 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 7 ms 8428 KB Output is correct
21 Correct 1 ms 1004 KB Output is correct
22 Correct 1 ms 1004 KB Output is correct
23 Correct 5 ms 6380 KB Output is correct
24 Correct 8 ms 7532 KB Output is correct
25 Correct 3 ms 2412 KB Output is correct
26 Correct 7 ms 7276 KB Output is correct
27 Correct 7 ms 7788 KB Output is correct
28 Correct 8 ms 8428 KB Output is correct
29 Correct 12 ms 8428 KB Output is correct
30 Correct 7 ms 8300 KB Output is correct
31 Correct 7 ms 8428 KB Output is correct
32 Correct 8 ms 8428 KB Output is correct
33 Correct 11 ms 8428 KB Output is correct
34 Correct 9 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1148 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 1 ms 1388 KB Output is correct
13 Correct 1 ms 1388 KB Output is correct
14 Correct 2 ms 1388 KB Output is correct
15 Correct 2 ms 1408 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 3 ms 3436 KB Output is correct
18 Correct 1 ms 1004 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 7 ms 8428 KB Output is correct
21 Correct 1 ms 1004 KB Output is correct
22 Correct 1 ms 1004 KB Output is correct
23 Correct 5 ms 6380 KB Output is correct
24 Correct 7 ms 7532 KB Output is correct
25 Correct 3 ms 2412 KB Output is correct
26 Correct 7 ms 7276 KB Output is correct
27 Correct 8 ms 7788 KB Output is correct
28 Correct 11 ms 8428 KB Output is correct
29 Correct 9 ms 8428 KB Output is correct
30 Correct 7 ms 8300 KB Output is correct
31 Correct 8 ms 8428 KB Output is correct
32 Correct 7 ms 8428 KB Output is correct
33 Correct 11 ms 8448 KB Output is correct
34 Correct 9 ms 8300 KB Output is correct
35 Correct 12 ms 7020 KB Output is correct
36 Correct 3 ms 1900 KB Output is correct
37 Correct 9 ms 5996 KB Output is correct
38 Correct 14 ms 7788 KB Output is correct
39 Correct 8 ms 1516 KB Output is correct
40 Correct 9 ms 1772 KB Output is correct
41 Correct 9 ms 2924 KB Output is correct
42 Correct 11 ms 7788 KB Output is correct
43 Correct 12 ms 8172 KB Output is correct
44 Correct 12 ms 8812 KB Output is correct
45 Correct 29 ms 9196 KB Output is correct
46 Correct 22 ms 9068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 1132 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 2 ms 1388 KB Output is correct
13 Correct 2 ms 1388 KB Output is correct
14 Correct 2 ms 1388 KB Output is correct
15 Correct 2 ms 1388 KB Output is correct
16 Correct 1 ms 1004 KB Output is correct
17 Correct 3 ms 3436 KB Output is correct
18 Correct 1 ms 1004 KB Output is correct
19 Correct 1 ms 1132 KB Output is correct
20 Correct 7 ms 8428 KB Output is correct
21 Correct 1 ms 1004 KB Output is correct
22 Correct 1 ms 1004 KB Output is correct
23 Correct 5 ms 6380 KB Output is correct
24 Correct 7 ms 7680 KB Output is correct
25 Correct 2 ms 2412 KB Output is correct
26 Correct 6 ms 7276 KB Output is correct
27 Correct 6 ms 7788 KB Output is correct
28 Correct 8 ms 8428 KB Output is correct
29 Correct 10 ms 8428 KB Output is correct
30 Correct 9 ms 8300 KB Output is correct
31 Correct 8 ms 8428 KB Output is correct
32 Correct 7 ms 8428 KB Output is correct
33 Correct 11 ms 8448 KB Output is correct
34 Correct 9 ms 8300 KB Output is correct
35 Correct 16 ms 7020 KB Output is correct
36 Correct 3 ms 1900 KB Output is correct
37 Correct 11 ms 5996 KB Output is correct
38 Correct 14 ms 7788 KB Output is correct
39 Correct 11 ms 1516 KB Output is correct
40 Correct 9 ms 1772 KB Output is correct
41 Correct 9 ms 2924 KB Output is correct
42 Correct 11 ms 7788 KB Output is correct
43 Correct 16 ms 8172 KB Output is correct
44 Correct 12 ms 8812 KB Output is correct
45 Correct 31 ms 9196 KB Output is correct
46 Correct 19 ms 9068 KB Output is correct
47 Correct 20 ms 12396 KB Output is correct
48 Correct 8 ms 1772 KB Output is correct
49 Correct 8 ms 1772 KB Output is correct
50 Correct 6 ms 1516 KB Output is correct
51 Correct 73 ms 77160 KB Output is correct
52 Correct 84 ms 88300 KB Output is correct
53 Correct 24 ms 18796 KB Output is correct
54 Correct 46 ms 61292 KB Output is correct
55 Correct 59 ms 77932 KB Output is correct
56 Correct 110 ms 112512 KB Output is correct
57 Correct 3 ms 2668 KB Output is correct
58 Correct 91 ms 111468 KB Output is correct
59 Correct 87 ms 103916 KB Output is correct
60 Correct 88 ms 103916 KB Output is correct
61 Correct 85 ms 98796 KB Output is correct
62 Correct 139 ms 112572 KB Output is correct
63 Correct 268 ms 111980 KB Output is correct
64 Correct 366 ms 111980 KB Output is correct
65 Correct 462 ms 112300 KB Output is correct
66 Correct 736 ms 111980 KB Output is correct
67 Correct 360 ms 111748 KB Output is correct