답안 #229546

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
229546 2020-05-05T02:39:40 Z frodakcin Jakarta Skyscrapers (APIO15_skyscraper) C++11
100 / 100
101 ms 2304 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>

const int MN = 3e4 + 10;
int N, M, st, end;
std::vector<int> a[MN];
struct state {public: int b, p, d, j;};
std::queue<state> q;
bool u[MN];

int main(void)
{
	scanf("%d%d", &N, &M);
	for(int i=0,b,p;i<M;++i)
	{
		scanf("%d%d", &b, &p);
		if(i == 0) st = b;
		if(i==1) end = b;
		else a[b].push_back(p);
	}
	if(st == end)
		return printf("0\n"), 0;
	for(int i=0;i<N;++i)
		std::sort(a[i].begin(), a[i].end()), a[i].resize(std::distance(a[i].begin(), std::unique(a[i].begin(), a[i].end())));
	for(int x : a[st])
	{
		if(st >= x) q.push({st-x, x, 1, -1});
		if(st+x<N) q.push({st+x, x, 1, 1});
	}
	u[st] = 1;
	for(;!q.empty();q.pop())
	{
		state n = q.front();
		if(n.b == end)
			return printf("%d\n", n.d), 0;
		if(!u[n.b])
		{
			u[n.b] = 1;
			for(int x : a[n.b])
			{
				if(x == n.p) continue;
				if(n.b >= x) q.push({n.b-x, x, n.d+1, -1});
				if(n.b+x<N) q.push({n.b+x, x, n.d+1, 1});
			}
		}
		else
		{
			std::vector<int>::iterator it = std::lower_bound(a[n.b].begin(), a[n.b].end(), n.p);
			if(it != a[n.b].end() && *it == n.p) continue;
		}
		int nx = n.b + n.p*n.j;
		if(0 <= nx && nx < N)
			q.push({nx, n.p, n.d+1, n.j});
	}
	printf("-1\n");
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
skyscraper.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &b, &p);
   ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 1024 KB Output is correct
3 Correct 5 ms 1024 KB Output is correct
4 Correct 5 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 1056 KB Output is correct
3 Correct 5 ms 1024 KB Output is correct
4 Correct 5 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 5 ms 1024 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 1024 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
12 Correct 5 ms 1024 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 6 ms 1024 KB Output is correct
15 Correct 5 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 1024 KB Output is correct
3 Correct 5 ms 1024 KB Output is correct
4 Correct 5 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 5 ms 1024 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 1024 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
12 Correct 5 ms 1024 KB Output is correct
13 Correct 6 ms 1024 KB Output is correct
14 Correct 6 ms 1024 KB Output is correct
15 Correct 5 ms 1024 KB Output is correct
16 Correct 5 ms 1056 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 5 ms 1024 KB Output is correct
19 Correct 5 ms 1024 KB Output is correct
20 Correct 5 ms 1024 KB Output is correct
21 Correct 5 ms 1024 KB Output is correct
22 Correct 6 ms 1024 KB Output is correct
23 Correct 5 ms 1024 KB Output is correct
24 Correct 6 ms 1024 KB Output is correct
25 Correct 5 ms 1024 KB Output is correct
26 Correct 5 ms 1024 KB Output is correct
27 Correct 6 ms 1024 KB Output is correct
28 Correct 6 ms 1024 KB Output is correct
29 Correct 6 ms 1024 KB Output is correct
30 Correct 5 ms 1024 KB Output is correct
31 Correct 5 ms 1024 KB Output is correct
32 Correct 5 ms 1024 KB Output is correct
33 Correct 7 ms 1024 KB Output is correct
34 Correct 6 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 1024 KB Output is correct
3 Correct 5 ms 1024 KB Output is correct
4 Correct 5 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 5 ms 1024 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 1024 KB Output is correct
11 Correct 5 ms 1024 KB Output is correct
12 Correct 5 ms 1024 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 1024 KB Output is correct
15 Correct 5 ms 1024 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 5 ms 1024 KB Output is correct
19 Correct 5 ms 1024 KB Output is correct
20 Correct 5 ms 1024 KB Output is correct
21 Correct 5 ms 1024 KB Output is correct
22 Correct 5 ms 1024 KB Output is correct
23 Correct 5 ms 1024 KB Output is correct
24 Correct 7 ms 1024 KB Output is correct
25 Correct 5 ms 1024 KB Output is correct
26 Correct 5 ms 1024 KB Output is correct
27 Correct 5 ms 1024 KB Output is correct
28 Correct 6 ms 1152 KB Output is correct
29 Correct 6 ms 1024 KB Output is correct
30 Correct 5 ms 1024 KB Output is correct
31 Correct 5 ms 1024 KB Output is correct
32 Correct 5 ms 1024 KB Output is correct
33 Correct 7 ms 1024 KB Output is correct
34 Correct 6 ms 1024 KB Output is correct
35 Correct 13 ms 1536 KB Output is correct
36 Correct 6 ms 1024 KB Output is correct
37 Correct 11 ms 1536 KB Output is correct
38 Correct 14 ms 1408 KB Output is correct
39 Correct 14 ms 1280 KB Output is correct
40 Correct 13 ms 1280 KB Output is correct
41 Correct 14 ms 1408 KB Output is correct
42 Correct 10 ms 1280 KB Output is correct
43 Correct 11 ms 1280 KB Output is correct
44 Correct 11 ms 1280 KB Output is correct
45 Correct 19 ms 1664 KB Output is correct
46 Correct 19 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1024 KB Output is correct
2 Correct 5 ms 1024 KB Output is correct
3 Correct 5 ms 1024 KB Output is correct
4 Correct 5 ms 1024 KB Output is correct
5 Correct 5 ms 1024 KB Output is correct
6 Correct 5 ms 1024 KB Output is correct
7 Correct 5 ms 1024 KB Output is correct
8 Correct 5 ms 1024 KB Output is correct
9 Correct 5 ms 1024 KB Output is correct
10 Correct 5 ms 1024 KB Output is correct
11 Correct 6 ms 1024 KB Output is correct
12 Correct 5 ms 1024 KB Output is correct
13 Correct 5 ms 1024 KB Output is correct
14 Correct 5 ms 1024 KB Output is correct
15 Correct 5 ms 1024 KB Output is correct
16 Correct 5 ms 1024 KB Output is correct
17 Correct 5 ms 1024 KB Output is correct
18 Correct 5 ms 1024 KB Output is correct
19 Correct 5 ms 1024 KB Output is correct
20 Correct 5 ms 1024 KB Output is correct
21 Correct 5 ms 1024 KB Output is correct
22 Correct 5 ms 1024 KB Output is correct
23 Correct 5 ms 1024 KB Output is correct
24 Correct 6 ms 1024 KB Output is correct
25 Correct 5 ms 1024 KB Output is correct
26 Correct 5 ms 1024 KB Output is correct
27 Correct 5 ms 1024 KB Output is correct
28 Correct 6 ms 1152 KB Output is correct
29 Correct 6 ms 1024 KB Output is correct
30 Correct 5 ms 1024 KB Output is correct
31 Correct 5 ms 1024 KB Output is correct
32 Correct 5 ms 1024 KB Output is correct
33 Correct 7 ms 1024 KB Output is correct
34 Correct 6 ms 1024 KB Output is correct
35 Correct 13 ms 1408 KB Output is correct
36 Correct 6 ms 1024 KB Output is correct
37 Correct 10 ms 1536 KB Output is correct
38 Correct 14 ms 1408 KB Output is correct
39 Correct 17 ms 1408 KB Output is correct
40 Correct 14 ms 1280 KB Output is correct
41 Correct 14 ms 1408 KB Output is correct
42 Correct 13 ms 1280 KB Output is correct
43 Correct 11 ms 1280 KB Output is correct
44 Correct 11 ms 1280 KB Output is correct
45 Correct 19 ms 1664 KB Output is correct
46 Correct 16 ms 1664 KB Output is correct
47 Correct 13 ms 1536 KB Output is correct
48 Correct 14 ms 1408 KB Output is correct
49 Correct 13 ms 1408 KB Output is correct
50 Correct 10 ms 1408 KB Output is correct
51 Correct 18 ms 1792 KB Output is correct
52 Correct 18 ms 1792 KB Output is correct
53 Correct 16 ms 1664 KB Output is correct
54 Correct 5 ms 1024 KB Output is correct
55 Correct 5 ms 1024 KB Output is correct
56 Correct 15 ms 1920 KB Output is correct
57 Correct 6 ms 1024 KB Output is correct
58 Correct 11 ms 1280 KB Output is correct
59 Correct 12 ms 1536 KB Output is correct
60 Correct 12 ms 1536 KB Output is correct
61 Correct 12 ms 1536 KB Output is correct
62 Correct 29 ms 2304 KB Output is correct
63 Correct 43 ms 1792 KB Output is correct
64 Correct 49 ms 1784 KB Output is correct
65 Correct 64 ms 1912 KB Output is correct
66 Correct 101 ms 1920 KB Output is correct
67 Correct 61 ms 1920 KB Output is correct