Submission #519865

# Submission time Handle Problem Language Result Execution time Memory
519865 2022-01-27T12:58:27 Z naal Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
13 ms 1832 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 = 3e3 + 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;
		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:63:20: warning: 'init' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |   cout << find(init);
      |                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 392 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 420 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 392 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 396 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 380 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 400 KB Output is correct
23 Correct 1 ms 972 KB Output is correct
24 Correct 1 ms 1100 KB Output is correct
25 Correct 1 ms 972 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
27 Correct 2 ms 1100 KB Output is correct
28 Correct 2 ms 1172 KB Output is correct
29 Correct 2 ms 1100 KB Output is correct
30 Correct 1 ms 1100 KB Output is correct
31 Correct 2 ms 1100 KB Output is correct
32 Correct 1 ms 1100 KB Output is correct
33 Correct 3 ms 1172 KB Output is correct
34 Correct 2 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 400 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 1 ms 400 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 972 KB Output is correct
24 Correct 2 ms 1100 KB Output is correct
25 Correct 1 ms 972 KB Output is correct
26 Correct 2 ms 1060 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 2 ms 1100 KB Output is correct
29 Correct 2 ms 1100 KB Output is correct
30 Correct 2 ms 1100 KB Output is correct
31 Correct 1 ms 1100 KB Output is correct
32 Correct 2 ms 1100 KB Output is correct
33 Correct 4 ms 1100 KB Output is correct
34 Correct 2 ms 1168 KB Output is correct
35 Correct 7 ms 1420 KB Output is correct
36 Correct 2 ms 844 KB Output is correct
37 Correct 5 ms 1612 KB Output is correct
38 Correct 6 ms 1484 KB Output is correct
39 Correct 6 ms 844 KB Output is correct
40 Correct 6 ms 1228 KB Output is correct
41 Correct 6 ms 1740 KB Output is correct
42 Correct 5 ms 1396 KB Output is correct
43 Correct 4 ms 1484 KB Output is correct
44 Correct 4 ms 1484 KB Output is correct
45 Correct 11 ms 1832 KB Output is correct
46 Correct 13 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 392 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 396 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 412 KB Output is correct
17 Correct 1 ms 716 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 972 KB Output is correct
24 Correct 2 ms 1100 KB Output is correct
25 Correct 1 ms 972 KB Output is correct
26 Correct 1 ms 1100 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 2 ms 1100 KB Output is correct
29 Correct 2 ms 1092 KB Output is correct
30 Correct 1 ms 1100 KB Output is correct
31 Correct 1 ms 1100 KB Output is correct
32 Correct 1 ms 1100 KB Output is correct
33 Correct 3 ms 1100 KB Output is correct
34 Correct 2 ms 1100 KB Output is correct
35 Correct 7 ms 1228 KB Output is correct
36 Correct 1 ms 844 KB Output is correct
37 Correct 5 ms 1444 KB Output is correct
38 Correct 7 ms 1356 KB Output is correct
39 Correct 7 ms 648 KB Output is correct
40 Correct 6 ms 1116 KB Output is correct
41 Correct 6 ms 1612 KB Output is correct
42 Correct 4 ms 1356 KB Output is correct
43 Correct 4 ms 1356 KB Output is correct
44 Correct 4 ms 1356 KB Output is correct
45 Correct 11 ms 1700 KB Output is correct
46 Correct 7 ms 1612 KB Output is correct
47 Runtime error 6 ms 1736 KB Execution killed with signal 11
48 Halted 0 ms 0 KB -