Submission #152155

# Submission time Handle Problem Language Result Execution time Memory
152155 2019-09-06T15:49:34 Z songc Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 39364 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, M, S, E;
vector<int> D[30303];
set<pii> dchk;
bool bchk[30303];

struct Data{
	int x, y, d;
};
deque<Data> Q;

int main(){
	scanf("%d %d", &N, &M);
	
	int x, y;
	scanf("%d %d", &x, &y);
	D[x].push_back(y);
	S = x;

	scanf("%d %d", &x, &y);
	D[x].push_back(y);
	E = x;

	for (int i=3; i<=M; i++){
		scanf("%d %d", &x, &y);
		D[x].push_back(y);
	}

	for (int v : D[S]){
		if (dchk.find(pii(S, v)) == dchk.end()){
			Q.push_back((Data){S, v, 0});
			dchk.insert(pii(S, v));
		}
	}
	bchk[S] = true;

	while (!Q.empty()){
		Data T = Q.front();
		Q.pop_front();
		if (T.x == E){
			printf("%d\n", T.d);
			return 0;
		}
		if (!bchk[T.x]){
			for (int v : D[T.x]){
				if (dchk.find(pii(T.x, v)) == dchk.end()){
					Q.push_front((Data){T.x, v, T.d});
					dchk.insert(pii(T.x, v));
				}
			}
			bchk[T.x] = true;
		}

		if (T.x-T.y >= 0 && dchk.find(pii(T.x-T.y, T.y)) == dchk.end()){
			Q.push_back((Data){T.x-T.y, T.y, T.d+1});
			dchk.insert(pii(T.x-T.y, T.y));
		}

		if (T.x+T.y < N && dchk.find(pii(T.x+T.y, T.y)) == dchk.end()){
			Q.push_back((Data){T.x+T.y, T.y, T.d+1});
			dchk.insert(pii(T.x+T.y, T.y));
		}
	}

	puts("-1");
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:17: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:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &x, &y);
  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &x, &y);
  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1012 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1016 KB Output is correct
14 Correct 5 ms 1400 KB Output is correct
15 Correct 4 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 3 ms 988 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1016 KB Output is correct
9 Correct 4 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1148 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1016 KB Output is correct
14 Correct 6 ms 1400 KB Output is correct
15 Correct 4 ms 1272 KB Output is correct
16 Correct 3 ms 1016 KB Output is correct
17 Correct 5 ms 1272 KB Output is correct
18 Correct 3 ms 1016 KB Output is correct
19 Correct 3 ms 1016 KB Output is correct
20 Correct 4 ms 1144 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1016 KB Output is correct
23 Correct 5 ms 1272 KB Output is correct
24 Correct 6 ms 1400 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 4 ms 1144 KB Output is correct
27 Correct 5 ms 1272 KB Output is correct
28 Correct 14 ms 2040 KB Output is correct
29 Correct 48 ms 3936 KB Output is correct
30 Correct 11 ms 1776 KB Output is correct
31 Correct 22 ms 2552 KB Output is correct
32 Correct 16 ms 2168 KB Output is correct
33 Correct 112 ms 6816 KB Output is correct
34 Correct 51 ms 4160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1020 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 1064 KB Output is correct
4 Correct 2 ms 1016 KB Output is correct
5 Correct 2 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 3 ms 1112 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1148 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 4 ms 1016 KB Output is correct
14 Correct 8 ms 1400 KB Output is correct
15 Correct 4 ms 1276 KB Output is correct
16 Correct 3 ms 1016 KB Output is correct
17 Correct 5 ms 1272 KB Output is correct
18 Correct 3 ms 1016 KB Output is correct
19 Correct 3 ms 1016 KB Output is correct
20 Correct 4 ms 1148 KB Output is correct
21 Correct 3 ms 988 KB Output is correct
22 Correct 3 ms 1016 KB Output is correct
23 Correct 5 ms 1272 KB Output is correct
24 Correct 7 ms 1400 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 4 ms 1272 KB Output is correct
27 Correct 5 ms 1272 KB Output is correct
28 Correct 14 ms 2044 KB Output is correct
29 Correct 48 ms 3908 KB Output is correct
30 Correct 11 ms 1784 KB Output is correct
31 Correct 22 ms 2644 KB Output is correct
32 Correct 15 ms 2136 KB Output is correct
33 Correct 108 ms 6776 KB Output is correct
34 Correct 61 ms 4184 KB Output is correct
35 Correct 33 ms 3832 KB Output is correct
36 Correct 5 ms 1148 KB Output is correct
37 Correct 22 ms 2936 KB Output is correct
38 Correct 35 ms 4088 KB Output is correct
39 Correct 11 ms 1528 KB Output is correct
40 Correct 12 ms 1656 KB Output is correct
41 Correct 16 ms 2168 KB Output is correct
42 Correct 9 ms 1528 KB Output is correct
43 Correct 10 ms 1656 KB Output is correct
44 Correct 9 ms 1528 KB Output is correct
45 Correct 649 ms 24448 KB Output is correct
46 Correct 278 ms 14700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1016 KB Output is correct
2 Correct 2 ms 1016 KB Output is correct
3 Correct 3 ms 1016 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 3 ms 1016 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1016 KB Output is correct
8 Correct 2 ms 1016 KB Output is correct
9 Correct 3 ms 1016 KB Output is correct
10 Correct 3 ms 1016 KB Output is correct
11 Correct 3 ms 1144 KB Output is correct
12 Correct 3 ms 1016 KB Output is correct
13 Correct 3 ms 1016 KB Output is correct
14 Correct 6 ms 1272 KB Output is correct
15 Correct 4 ms 1272 KB Output is correct
16 Correct 3 ms 1016 KB Output is correct
17 Correct 5 ms 1272 KB Output is correct
18 Correct 3 ms 1144 KB Output is correct
19 Correct 3 ms 1144 KB Output is correct
20 Correct 4 ms 1144 KB Output is correct
21 Correct 3 ms 1016 KB Output is correct
22 Correct 3 ms 1144 KB Output is correct
23 Correct 5 ms 1272 KB Output is correct
24 Correct 6 ms 1372 KB Output is correct
25 Correct 4 ms 1144 KB Output is correct
26 Correct 4 ms 1272 KB Output is correct
27 Correct 5 ms 1272 KB Output is correct
28 Correct 14 ms 2040 KB Output is correct
29 Correct 47 ms 3892 KB Output is correct
30 Correct 12 ms 1912 KB Output is correct
31 Correct 23 ms 2680 KB Output is correct
32 Correct 16 ms 2168 KB Output is correct
33 Correct 109 ms 6708 KB Output is correct
34 Correct 52 ms 4088 KB Output is correct
35 Correct 34 ms 3832 KB Output is correct
36 Correct 5 ms 1144 KB Output is correct
37 Correct 22 ms 2936 KB Output is correct
38 Correct 35 ms 4088 KB Output is correct
39 Correct 11 ms 1656 KB Output is correct
40 Correct 12 ms 1656 KB Output is correct
41 Correct 16 ms 2168 KB Output is correct
42 Correct 9 ms 1528 KB Output is correct
43 Correct 10 ms 1656 KB Output is correct
44 Correct 10 ms 1528 KB Output is correct
45 Correct 657 ms 24472 KB Output is correct
46 Correct 271 ms 14612 KB Output is correct
47 Correct 20 ms 2680 KB Output is correct
48 Correct 14 ms 1784 KB Output is correct
49 Correct 13 ms 1784 KB Output is correct
50 Correct 9 ms 1528 KB Output is correct
51 Correct 56 ms 4600 KB Output is correct
52 Correct 66 ms 5212 KB Output is correct
53 Correct 17 ms 2424 KB Output is correct
54 Correct 7 ms 1784 KB Output is correct
55 Correct 10 ms 2296 KB Output is correct
56 Correct 23 ms 3704 KB Output is correct
57 Correct 4 ms 1144 KB Output is correct
58 Correct 34 ms 4472 KB Output is correct
59 Correct 32 ms 4216 KB Output is correct
60 Correct 30 ms 4088 KB Output is correct
61 Correct 30 ms 3960 KB Output is correct
62 Correct 504 ms 23772 KB Output is correct
63 Execution timed out 1080 ms 39364 KB Time limit exceeded
64 Halted 0 ms 0 KB -