Submission #519723

# Submission time Handle Problem Language Result Execution time Memory
519723 2022-01-27T07:09:07 Z naal Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
101 ms 41280 KB
// https://oj.uz/problem/view/APIO15_skyscraper
#include <bits/stdc++.h>
using namespace std;

#define Fname ((string) "io")
#define int long long
#define ii pair <int, int>
#define iii pair <int, ii>
#define fi first
#define se second
#define endl '\n'
const int INF = 1e16;
const int N = 3e3 + 5;

int n, m, d[N][N], goal;
vector <int> a[N];
priority_queue <iii, vector <iii>, greater <iii>> pq;

int find(int u) {
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= n; j++)
			d[i][j] = INF;
	pq.push({0, {u, 0}});
	d[u][0] = 0;
	while (pq.size()) {
		u = pq.top().se.fi;
		int step = pq.top().se.se, total = pq.top().fi;
		pq.pop();
		if (total != d[u][step])
			continue;
		if (u == goal)
			return total;
		for (int &j : a[u])
			if (d[u][j] > total) {
				d[u][j] = total;
				pq.push({total, {u, j}});
			}
		if (u + step <= n && d[u + step][step] > total + 1) {
			d[u + step][step] = total + 1;
			pq.push({total + 1, {u + step, step}});
		}
		if (u - step > 0 && d[u - step][step] > total + 1) {
			d[u - step][step] = total + 1;
			pq.push({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:72:20: warning: 'init' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |   cout << find(init);
      |                    ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 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 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
# 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 0 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 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 0 ms 588 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 864 KB Output is correct
13 Correct 1 ms 844 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 2 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 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 0 ms 332 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 588 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 1 ms 844 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 5 ms 7756 KB Output is correct
18 Correct 14 ms 31280 KB Output is correct
19 Correct 17 ms 39636 KB Output is correct
20 Correct 18 ms 39796 KB Output is correct
21 Correct 2 ms 3148 KB Output is correct
22 Correct 16 ms 32332 KB Output is correct
23 Correct 13 ms 26828 KB Output is correct
24 Correct 17 ms 36300 KB Output is correct
25 Correct 18 ms 39704 KB Output is correct
26 Correct 18 ms 39716 KB Output is correct
27 Correct 18 ms 39756 KB Output is correct
28 Correct 20 ms 39780 KB Output is correct
29 Correct 23 ms 39772 KB Output is correct
30 Correct 19 ms 39820 KB Output is correct
31 Correct 22 ms 39724 KB Output is correct
32 Correct 20 ms 39756 KB Output is correct
33 Correct 30 ms 39752 KB Output is correct
34 Correct 26 ms 39808 KB Output is correct
# 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 0 ms 332 KB Output is correct
4 Correct 1 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 1 ms 460 KB Output is correct
9 Correct 0 ms 588 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 1 ms 844 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 4 ms 7756 KB Output is correct
18 Correct 14 ms 31216 KB Output is correct
19 Correct 17 ms 39628 KB Output is correct
20 Correct 18 ms 39756 KB Output is correct
21 Correct 1 ms 3148 KB Output is correct
22 Correct 15 ms 32332 KB Output is correct
23 Correct 13 ms 26828 KB Output is correct
24 Correct 18 ms 36236 KB Output is correct
25 Correct 18 ms 39756 KB Output is correct
26 Correct 19 ms 39756 KB Output is correct
27 Correct 19 ms 39756 KB Output is correct
28 Correct 20 ms 39756 KB Output is correct
29 Correct 24 ms 39712 KB Output is correct
30 Correct 19 ms 39760 KB Output is correct
31 Correct 21 ms 39692 KB Output is correct
32 Correct 20 ms 39704 KB Output is correct
33 Correct 32 ms 39756 KB Output is correct
34 Correct 26 ms 39756 KB Output is correct
35 Correct 22 ms 23368 KB Output is correct
36 Correct 10 ms 14156 KB Output is correct
37 Correct 25 ms 38828 KB Output is correct
38 Correct 25 ms 40588 KB Output is correct
39 Correct 23 ms 40396 KB Output is correct
40 Correct 22 ms 40336 KB Output is correct
41 Correct 24 ms 40524 KB Output is correct
42 Correct 21 ms 40264 KB Output is correct
43 Correct 21 ms 40268 KB Output is correct
44 Correct 24 ms 40256 KB Output is correct
45 Correct 101 ms 41220 KB Output is correct
46 Correct 86 ms 41184 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 0 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 460 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 844 KB Output is correct
11 Correct 1 ms 844 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 1 ms 844 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
16 Correct 1 ms 1484 KB Output is correct
17 Correct 4 ms 7756 KB Output is correct
18 Correct 14 ms 31268 KB Output is correct
19 Correct 17 ms 39728 KB Output is correct
20 Correct 18 ms 39696 KB Output is correct
21 Correct 2 ms 3148 KB Output is correct
22 Correct 15 ms 32332 KB Output is correct
23 Correct 13 ms 26752 KB Output is correct
24 Correct 18 ms 36300 KB Output is correct
25 Correct 19 ms 39744 KB Output is correct
26 Correct 18 ms 39756 KB Output is correct
27 Correct 20 ms 39756 KB Output is correct
28 Correct 20 ms 39672 KB Output is correct
29 Correct 24 ms 39800 KB Output is correct
30 Correct 20 ms 39712 KB Output is correct
31 Correct 21 ms 39756 KB Output is correct
32 Correct 20 ms 39756 KB Output is correct
33 Correct 37 ms 39756 KB Output is correct
34 Correct 26 ms 39804 KB Output is correct
35 Correct 28 ms 23360 KB Output is correct
36 Correct 8 ms 14156 KB Output is correct
37 Correct 25 ms 38832 KB Output is correct
38 Correct 26 ms 40592 KB Output is correct
39 Correct 22 ms 40408 KB Output is correct
40 Correct 22 ms 40372 KB Output is correct
41 Correct 25 ms 40516 KB Output is correct
42 Correct 21 ms 40264 KB Output is correct
43 Correct 21 ms 40260 KB Output is correct
44 Correct 22 ms 40296 KB Output is correct
45 Correct 98 ms 41160 KB Output is correct
46 Correct 70 ms 41280 KB Output is correct
47 Runtime error 7 ms 2124 KB Execution killed with signal 6
48 Halted 0 ms 0 KB -