답안 #519871

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519871 2022-01-27T13:09:30 Z naal Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
380 ms 112452 KB
// https://oj.uz/problem/view/APIO15_skyscraper
#include <bits/stdc++.h>
using namespace std;
 
#define Fname ((string) "io")
#define ii pair <int, int>
#define iii pair <int, ii>
#define fi first
#define se second
#define endl '\n'
const int N = 3e4 + 5;
 
int n, m, goal;
bitset <N> d[N], used;
vector <int> a[N];
deque <iii> dq;
 
int find(int u) {
	dq.push_back({0, {u, 0}});
	while (dq.size()) {
		u = dq.front().se.fi;
		int step = dq.front().se.se, total = dq.front().fi;
		dq.pop_front();
		if (u == goal)
			return total;
		if (d[u][step])
			continue;
		d[u][step] = 1;
		if (!used[u]) {
			// used[u] = 1;
			for (int &step : a[u])
				if (!d[u][step])
					dq.push_front({total, {u, step}});
		}
		if (u + step <= n && !d[u + step][step]) 
			dq.push_back({total + 1, {u + step, step}});
		if (u - step > 0 && !d[u - step][step])
			dq.push_back({total + 1, {u - step, step}});
	}
	return -1;
}
 
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef lan_ngu
		freopen((Fname + ".inp").c_str(), "r", stdin);
		freopen((Fname + ".out").c_str(), "w", stdout);
	#endif
 
	// int _nt; cin >> _nt;
	int _nt = 1;
	while (_nt--) {
		cin >> n >> m;
		int init;
		for (int i = 1; i <= m; i++) {
			int b, p; cin >> b >> p;
			b++;
			a[b].push_back(p);
			if (i == 1)
				init = b;
			else if (i == 2)
				goal = b;
		}	
		cout << find(init);
	}
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:65:20: warning: 'init' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |   cout << find(init);
      |                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 1052 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 1356 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 3 ms 3020 KB Output is correct
18 Correct 1 ms 1036 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 6 ms 8396 KB Output is correct
21 Correct 2 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 4 ms 6348 KB Output is correct
24 Correct 5 ms 7500 KB Output is correct
25 Correct 2 ms 2380 KB Output is correct
26 Correct 4 ms 7244 KB Output is correct
27 Correct 4 ms 7628 KB Output is correct
28 Correct 7 ms 8396 KB Output is correct
29 Correct 7 ms 8268 KB Output is correct
30 Correct 5 ms 8268 KB Output is correct
31 Correct 6 ms 8344 KB Output is correct
32 Correct 5 ms 8328 KB Output is correct
33 Correct 9 ms 8396 KB Output is correct
34 Correct 7 ms 8396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1028 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 1028 KB Output is correct
9 Correct 1 ms 1032 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 1228 KB Output is correct
13 Correct 1 ms 1356 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 3 ms 2892 KB Output is correct
18 Correct 1 ms 1028 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 5 ms 8396 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 4 ms 6348 KB Output is correct
24 Correct 5 ms 7500 KB Output is correct
25 Correct 2 ms 2380 KB Output is correct
26 Correct 5 ms 7244 KB Output is correct
27 Correct 5 ms 7628 KB Output is correct
28 Correct 7 ms 8396 KB Output is correct
29 Correct 6 ms 8348 KB Output is correct
30 Correct 5 ms 8268 KB Output is correct
31 Correct 7 ms 8268 KB Output is correct
32 Correct 5 ms 8268 KB Output is correct
33 Correct 8 ms 8396 KB Output is correct
34 Correct 7 ms 8436 KB Output is correct
35 Correct 13 ms 6900 KB Output is correct
36 Correct 2 ms 2252 KB Output is correct
37 Correct 8 ms 6348 KB Output is correct
38 Correct 9 ms 4300 KB Output is correct
39 Correct 6 ms 1484 KB Output is correct
40 Correct 7 ms 2380 KB Output is correct
41 Correct 13 ms 8012 KB Output is correct
42 Correct 8 ms 7628 KB Output is correct
43 Correct 8 ms 8080 KB Output is correct
44 Correct 8 ms 8780 KB Output is correct
45 Correct 43 ms 9412 KB Output is correct
46 Correct 38 ms 9244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 1 ms 972 KB Output is correct
12 Correct 1 ms 1276 KB Output is correct
13 Correct 1 ms 1364 KB Output is correct
14 Correct 2 ms 1432 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 1 ms 1040 KB Output is correct
17 Correct 2 ms 2896 KB Output is correct
18 Correct 1 ms 976 KB Output is correct
19 Correct 1 ms 976 KB Output is correct
20 Correct 5 ms 8400 KB Output is correct
21 Correct 1 ms 976 KB Output is correct
22 Correct 1 ms 976 KB Output is correct
23 Correct 4 ms 6352 KB Output is correct
24 Correct 5 ms 7504 KB Output is correct
25 Correct 2 ms 2320 KB Output is correct
26 Correct 4 ms 7252 KB Output is correct
27 Correct 5 ms 7632 KB Output is correct
28 Correct 6 ms 8404 KB Output is correct
29 Correct 7 ms 8268 KB Output is correct
30 Correct 5 ms 8268 KB Output is correct
31 Correct 5 ms 8268 KB Output is correct
32 Correct 5 ms 8324 KB Output is correct
33 Correct 7 ms 8396 KB Output is correct
34 Correct 6 ms 8332 KB Output is correct
35 Correct 11 ms 6860 KB Output is correct
36 Correct 3 ms 2256 KB Output is correct
37 Correct 8 ms 6392 KB Output is correct
38 Correct 9 ms 4300 KB Output is correct
39 Correct 7 ms 1484 KB Output is correct
40 Correct 8 ms 2380 KB Output is correct
41 Correct 12 ms 8052 KB Output is correct
42 Correct 7 ms 7628 KB Output is correct
43 Correct 10 ms 8132 KB Output is correct
44 Correct 8 ms 8780 KB Output is correct
45 Correct 43 ms 9412 KB Output is correct
46 Correct 39 ms 9284 KB Output is correct
47 Correct 18 ms 20128 KB Output is correct
48 Correct 5 ms 1740 KB Output is correct
49 Correct 5 ms 1612 KB Output is correct
50 Correct 4 ms 1484 KB Output is correct
51 Correct 57 ms 79920 KB Output is correct
52 Correct 58 ms 87104 KB Output is correct
53 Correct 17 ms 18640 KB Output is correct
54 Correct 35 ms 61188 KB Output is correct
55 Correct 45 ms 77860 KB Output is correct
56 Correct 64 ms 112192 KB Output is correct
57 Correct 2 ms 2580 KB Output is correct
58 Correct 64 ms 111704 KB Output is correct
59 Correct 62 ms 103840 KB Output is correct
60 Correct 63 ms 103864 KB Output is correct
61 Correct 61 ms 98784 KB Output is correct
62 Correct 116 ms 112452 KB Output is correct
63 Correct 152 ms 111808 KB Output is correct
64 Correct 183 ms 111820 KB Output is correct
65 Correct 214 ms 112000 KB Output is correct
66 Correct 380 ms 112240 KB Output is correct
67 Correct 222 ms 112064 KB Output is correct