Submission #519685

# Submission time Handle Problem Language Result Execution time Memory
519685 2022-01-27T04:09:07 Z naal Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
23 ms 39940 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}});
	for (int  j = 0; j <= n; j++)
		d[u][j] = 0;
	while (pq.size()) {
		u = pq.top().se.fi;
		int step = pq.top().se.se, total = pq.top().fi;
		pq.pop();
		if (u == goal)
			return total;
		if (total != d[u][step])
			continue;
		a[u].push_back(step);
		for (int &step : a[u]) {
			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}});
			}		
		}
		a[u].pop_back();
	}
	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;
			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:71:20: warning: 'init' may be used uninitialized in this function [-Wmaybe-uninitialized]
   71 |   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 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 392 KB Output is correct
7 Correct 1 ms 392 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 388 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 396 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 768 KB Output is correct
11 Correct 1 ms 908 KB Output is correct
12 Correct 1 ms 844 KB Output is correct
13 Correct 1 ms 908 KB Output is correct
14 Correct 2 ms 972 KB Output is correct
15 Correct 1 ms 1048 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 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 0 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 904 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 2 ms 1036 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 31308 KB Output is correct
19 Correct 17 ms 39688 KB Output is correct
20 Correct 18 ms 39708 KB Output is correct
21 Correct 2 ms 3148 KB Output is correct
22 Correct 15 ms 32376 KB Output is correct
23 Correct 18 ms 26828 KB Output is correct
24 Correct 18 ms 36340 KB Output is correct
25 Correct 18 ms 39752 KB Output is correct
26 Correct 21 ms 39832 KB Output is correct
27 Correct 21 ms 39908 KB Output is correct
28 Incorrect 20 ms 39732 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 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 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 0 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 648 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 16 ms 31308 KB Output is correct
19 Correct 18 ms 39632 KB Output is correct
20 Correct 21 ms 39824 KB Output is correct
21 Correct 2 ms 3148 KB Output is correct
22 Correct 17 ms 32312 KB Output is correct
23 Correct 14 ms 26816 KB Output is correct
24 Correct 19 ms 36428 KB Output is correct
25 Correct 18 ms 39756 KB Output is correct
26 Correct 19 ms 39820 KB Output is correct
27 Correct 18 ms 39788 KB Output is correct
28 Incorrect 20 ms 39680 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 388 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 0 ms 392 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 7808 KB Output is correct
18 Correct 15 ms 31308 KB Output is correct
19 Correct 20 ms 39680 KB Output is correct
20 Correct 22 ms 39940 KB Output is correct
21 Correct 2 ms 3216 KB Output is correct
22 Correct 16 ms 32332 KB Output is correct
23 Correct 14 ms 26832 KB Output is correct
24 Correct 21 ms 36372 KB Output is correct
25 Correct 20 ms 39768 KB Output is correct
26 Correct 20 ms 39756 KB Output is correct
27 Correct 23 ms 39732 KB Output is correct
28 Incorrect 18 ms 39812 KB Output isn't correct
29 Halted 0 ms 0 KB -