답안 #761703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761703 2023-06-20T07:20:28 Z MetalPower Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
215 ms 196312 KB
# include <bits/stdc++.h>
# define fi first
# define se second
# define ll long long
using namespace std;

const int sq = 200;
vector<int> dg[30001];
bitset<30001> jp[30001];
 
int st, js, ed;
int rc[30001];
bool ex[30001];

int l = 0, r = -1;
pair<pair<int, int>, int> BFS[9000001];
 
ll ch(int a, int b) {
	return (1ll * 1e9 * 1ll * a) + (1ll * b);	
}
 
int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	
	for(int i=0;i<N;i++) rc[i] = 1e9;
	for(int i=0;i<M;i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		if(i == 0) {
			st = a;
			js = b;
		} else if(i == 1) ed = a;
		else dg[a].push_back(b);
	}
	
	BFS[++r] = make_pair(make_pair(st, 0), js);
	while(l <= r) {
		int a, b, c;
		a = BFS[l].fi.fi;
		b = BFS[l].fi.se;
		c = BFS[l].se;
	//	cout<<a<<" "<<b<<" "<
		l++;

		rc[a] = min(rc[a], b);
		if(a == ed) break;
		if(a - c >= 0 && jp[a - c][c] == 0) {
			BFS[++r] = make_pair(make_pair(a - c, b + 1), c);
			jp[a - c][c] = 1;
		}
		if(a + c < N && jp[a + c][c] == 0) {
			BFS[++r] = make_pair(make_pair(a+c, b + 1), c);
			jp[a + c][c] = 1;
		}

		if(ex[a]) continue;
		ex[a] = true;
		
		for(int k=0;k<dg[a].size();k++) {
			
			c = dg[a][k];
			if(a - c >= 0 && jp[a - c][c] == 0) {
				BFS[++r] = make_pair(make_pair(a - c, b + 1), c);
				jp[a - c][c] = 1;
			}
			if(a + c < N && jp[a + c][c] == 0) {
				BFS[++r] = make_pair(make_pair(a+c, b + 1), c);
				jp[a + c][c] = 1;
			}
		}
	}
	if(rc[ed] == 1e9) rc[ed] = -1;
	printf("%d\n", rc[ed]);
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:60:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int k=0;k<dg[a].size();k++) {
      |               ~^~~~~~~~~~~~~
skyscraper.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d %d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~
skyscraper.cpp:29:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 1 ms 1412 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 3668 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 5 ms 8404 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 3 ms 6356 KB Output is correct
24 Correct 5 ms 7508 KB Output is correct
25 Correct 2 ms 2388 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7772 KB Output is correct
28 Correct 5 ms 8660 KB Output is correct
29 Correct 9 ms 9072 KB Output is correct
30 Correct 5 ms 8456 KB Output is correct
31 Correct 5 ms 8660 KB Output is correct
32 Correct 5 ms 8660 KB Output is correct
33 Correct 6 ms 9800 KB Output is correct
34 Correct 5 ms 9044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 2 ms 3668 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 4 ms 8404 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 3 ms 6336 KB Output is correct
24 Correct 4 ms 7508 KB Output is correct
25 Correct 2 ms 2388 KB Output is correct
26 Correct 4 ms 7304 KB Output is correct
27 Correct 4 ms 7764 KB Output is correct
28 Correct 5 ms 8660 KB Output is correct
29 Correct 5 ms 9044 KB Output is correct
30 Correct 4 ms 8472 KB Output is correct
31 Correct 5 ms 8764 KB Output is correct
32 Correct 5 ms 8660 KB Output is correct
33 Correct 9 ms 9748 KB Output is correct
34 Correct 5 ms 9044 KB Output is correct
35 Correct 8 ms 6812 KB Output is correct
36 Correct 2 ms 2900 KB Output is correct
37 Correct 8 ms 8532 KB Output is correct
38 Correct 9 ms 8916 KB Output is correct
39 Correct 6 ms 1748 KB Output is correct
40 Correct 7 ms 3924 KB Output is correct
41 Correct 9 ms 8020 KB Output is correct
42 Correct 8 ms 7508 KB Output is correct
43 Correct 8 ms 8020 KB Output is correct
44 Correct 8 ms 8544 KB Output is correct
45 Correct 14 ms 14164 KB Output is correct
46 Correct 11 ms 11732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 980 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1236 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 1 ms 980 KB Output is correct
17 Correct 3 ms 3668 KB Output is correct
18 Correct 1 ms 980 KB Output is correct
19 Correct 1 ms 980 KB Output is correct
20 Correct 5 ms 8404 KB Output is correct
21 Correct 1 ms 980 KB Output is correct
22 Correct 1 ms 980 KB Output is correct
23 Correct 4 ms 6356 KB Output is correct
24 Correct 5 ms 7508 KB Output is correct
25 Correct 2 ms 2388 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7764 KB Output is correct
28 Correct 5 ms 8660 KB Output is correct
29 Correct 5 ms 9064 KB Output is correct
30 Correct 4 ms 8532 KB Output is correct
31 Correct 5 ms 8724 KB Output is correct
32 Correct 5 ms 8624 KB Output is correct
33 Correct 6 ms 9684 KB Output is correct
34 Correct 5 ms 9020 KB Output is correct
35 Correct 8 ms 6740 KB Output is correct
36 Correct 3 ms 2900 KB Output is correct
37 Correct 7 ms 8532 KB Output is correct
38 Correct 10 ms 8892 KB Output is correct
39 Correct 6 ms 1732 KB Output is correct
40 Correct 7 ms 3924 KB Output is correct
41 Correct 9 ms 8020 KB Output is correct
42 Correct 10 ms 7508 KB Output is correct
43 Correct 8 ms 7940 KB Output is correct
44 Correct 8 ms 8560 KB Output is correct
45 Correct 13 ms 14132 KB Output is correct
46 Correct 11 ms 11672 KB Output is correct
47 Correct 20 ms 31680 KB Output is correct
48 Correct 5 ms 1492 KB Output is correct
49 Correct 5 ms 1492 KB Output is correct
50 Correct 4 ms 1492 KB Output is correct
51 Correct 49 ms 83532 KB Output is correct
52 Correct 53 ms 91372 KB Output is correct
53 Correct 15 ms 17500 KB Output is correct
54 Correct 29 ms 61500 KB Output is correct
55 Correct 36 ms 78256 KB Output is correct
56 Correct 58 ms 112532 KB Output is correct
57 Correct 2 ms 2772 KB Output is correct
58 Correct 57 ms 112320 KB Output is correct
59 Correct 52 ms 104396 KB Output is correct
60 Correct 52 ms 104444 KB Output is correct
61 Correct 50 ms 99268 KB Output is correct
62 Correct 74 ms 117192 KB Output is correct
63 Correct 106 ms 138224 KB Output is correct
64 Correct 135 ms 144372 KB Output is correct
65 Correct 144 ms 158952 KB Output is correct
66 Correct 215 ms 196312 KB Output is correct
67 Correct 136 ms 155028 KB Output is correct