답안 #76361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
76361 2018-09-13T04:07:54 Z shoemakerjo Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
163 ms 16504 KB
#include <bits/stdc++.h>

using namespace std;
#define maxn 30010
#define pii pair<int, int>

int N, M;
priority_queue<pii, vector<pii>, greater<pii>> pq;

const int inf = 987654321;
vector<vector<int>> mov(maxn);
int dist[maxn];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> M;
	int source, sink;
	int b, p;
	for (int i = 0; i < M; i++) {
		cin >> b >> p;
		mov[b].push_back(p);
		if (i == 0) source = b;
		if (i == 1) sink = b;
	}
	for (int i = 0; i < N-1; i++) {
		sort(mov[i].begin(), mov[i].end());
	}
	fill(dist, dist+maxn, inf);
	dist[source] = 0;

	pq.push(pii(0, source));
	while (pq.size()) {
		pii cur = pq.top(); pq.pop();
		int spot = cur.second;
		int d = cur.first;
		if (d > dist[spot]) continue;
		if (spot == sink) break;
		int prev = -1;

		for (int val : mov[spot]) {
			if (val == prev) continue;
			prev = val;
			for (int jp = 1; jp < N; jp++) {
				int nx = jp*val + spot;
				if (nx >= N) break;
				if (d + jp < dist[nx]) {
					dist[nx] = d+jp;
					pq.push(pii(d+jp, nx));
				}
				if (binary_search(mov[nx].begin(), mov[nx].end(), val)) break;
			}
			for (int jp = 1; jp < N; jp++) {
				int nx = spot - jp*val;
				if (nx < 0) break;
				if (nx >= N) break;
				if (d + jp < dist[nx]) {
					dist[nx] = d+jp;
					pq.push(pii(d+jp, nx));
				}
				if (binary_search(mov[nx].begin(), mov[nx].end(), val)) break;
			}
		}
	}



	if (dist[sink] == inf) dist[sink] = -1;
	cout << dist[sink] << endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:38:3: warning: 'sink' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (spot == sink) break;
   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1296 KB Output is correct
3 Correct 3 ms 1296 KB Output is correct
4 Correct 3 ms 1300 KB Output is correct
5 Correct 3 ms 1356 KB Output is correct
6 Correct 3 ms 1356 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1436 KB Output is correct
2 Correct 3 ms 1448 KB Output is correct
3 Correct 3 ms 1448 KB Output is correct
4 Correct 3 ms 1448 KB Output is correct
5 Correct 3 ms 1448 KB Output is correct
6 Correct 3 ms 1448 KB Output is correct
7 Correct 3 ms 1448 KB Output is correct
8 Correct 2 ms 1448 KB Output is correct
9 Correct 3 ms 1448 KB Output is correct
10 Correct 3 ms 1504 KB Output is correct
11 Correct 3 ms 1652 KB Output is correct
12 Correct 3 ms 1652 KB Output is correct
13 Correct 3 ms 1652 KB Output is correct
14 Correct 3 ms 1668 KB Output is correct
15 Correct 3 ms 1696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1696 KB Output is correct
2 Correct 3 ms 1696 KB Output is correct
3 Correct 3 ms 1696 KB Output is correct
4 Correct 3 ms 1696 KB Output is correct
5 Correct 3 ms 1696 KB Output is correct
6 Correct 3 ms 1696 KB Output is correct
7 Correct 3 ms 1696 KB Output is correct
8 Correct 3 ms 1696 KB Output is correct
9 Correct 4 ms 1696 KB Output is correct
10 Correct 4 ms 1696 KB Output is correct
11 Correct 4 ms 1804 KB Output is correct
12 Correct 3 ms 1804 KB Output is correct
13 Correct 3 ms 1804 KB Output is correct
14 Correct 3 ms 1804 KB Output is correct
15 Correct 3 ms 1804 KB Output is correct
16 Correct 3 ms 1804 KB Output is correct
17 Correct 4 ms 1908 KB Output is correct
18 Correct 3 ms 1908 KB Output is correct
19 Correct 3 ms 1908 KB Output is correct
20 Correct 4 ms 1944 KB Output is correct
21 Correct 3 ms 1944 KB Output is correct
22 Correct 3 ms 1944 KB Output is correct
23 Correct 3 ms 1944 KB Output is correct
24 Correct 4 ms 1992 KB Output is correct
25 Correct 4 ms 1992 KB Output is correct
26 Correct 3 ms 1992 KB Output is correct
27 Correct 5 ms 1992 KB Output is correct
28 Correct 5 ms 2064 KB Output is correct
29 Correct 5 ms 2212 KB Output is correct
30 Correct 4 ms 2212 KB Output is correct
31 Correct 5 ms 2212 KB Output is correct
32 Correct 5 ms 2212 KB Output is correct
33 Correct 8 ms 2360 KB Output is correct
34 Correct 6 ms 2372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2372 KB Output is correct
2 Correct 3 ms 2372 KB Output is correct
3 Correct 3 ms 2372 KB Output is correct
4 Correct 3 ms 2372 KB Output is correct
5 Correct 3 ms 2372 KB Output is correct
6 Correct 3 ms 2372 KB Output is correct
7 Correct 3 ms 2372 KB Output is correct
8 Correct 3 ms 2372 KB Output is correct
9 Correct 3 ms 2372 KB Output is correct
10 Correct 3 ms 2372 KB Output is correct
11 Correct 3 ms 2372 KB Output is correct
12 Correct 3 ms 2372 KB Output is correct
13 Correct 3 ms 2372 KB Output is correct
14 Correct 3 ms 2372 KB Output is correct
15 Correct 3 ms 2372 KB Output is correct
16 Correct 3 ms 2372 KB Output is correct
17 Correct 4 ms 2372 KB Output is correct
18 Correct 3 ms 2372 KB Output is correct
19 Correct 3 ms 2372 KB Output is correct
20 Correct 3 ms 2372 KB Output is correct
21 Correct 3 ms 2372 KB Output is correct
22 Correct 3 ms 2372 KB Output is correct
23 Correct 3 ms 2372 KB Output is correct
24 Correct 4 ms 2372 KB Output is correct
25 Correct 3 ms 2372 KB Output is correct
26 Correct 3 ms 2372 KB Output is correct
27 Correct 3 ms 2372 KB Output is correct
28 Correct 3 ms 2372 KB Output is correct
29 Correct 5 ms 2604 KB Output is correct
30 Correct 4 ms 2604 KB Output is correct
31 Correct 4 ms 2604 KB Output is correct
32 Correct 3 ms 2604 KB Output is correct
33 Correct 7 ms 2656 KB Output is correct
34 Correct 5 ms 2668 KB Output is correct
35 Correct 11 ms 2808 KB Output is correct
36 Correct 4 ms 2808 KB Output is correct
37 Correct 11 ms 3068 KB Output is correct
38 Correct 13 ms 3356 KB Output is correct
39 Correct 11 ms 3492 KB Output is correct
40 Correct 11 ms 3760 KB Output is correct
41 Correct 17 ms 4148 KB Output is correct
42 Correct 13 ms 4376 KB Output is correct
43 Correct 13 ms 4524 KB Output is correct
44 Correct 13 ms 4736 KB Output is correct
45 Correct 15 ms 5312 KB Output is correct
46 Correct 13 ms 5408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5408 KB Output is correct
2 Correct 3 ms 5408 KB Output is correct
3 Correct 3 ms 5408 KB Output is correct
4 Correct 3 ms 5408 KB Output is correct
5 Correct 3 ms 5408 KB Output is correct
6 Correct 3 ms 5408 KB Output is correct
7 Correct 3 ms 5408 KB Output is correct
8 Correct 3 ms 5408 KB Output is correct
9 Correct 4 ms 5408 KB Output is correct
10 Correct 3 ms 5408 KB Output is correct
11 Correct 3 ms 5408 KB Output is correct
12 Correct 3 ms 5408 KB Output is correct
13 Correct 4 ms 5408 KB Output is correct
14 Correct 4 ms 5408 KB Output is correct
15 Correct 3 ms 5408 KB Output is correct
16 Correct 4 ms 5408 KB Output is correct
17 Correct 4 ms 5408 KB Output is correct
18 Correct 4 ms 5408 KB Output is correct
19 Correct 4 ms 5408 KB Output is correct
20 Correct 3 ms 5408 KB Output is correct
21 Correct 3 ms 5408 KB Output is correct
22 Correct 3 ms 5408 KB Output is correct
23 Correct 3 ms 5408 KB Output is correct
24 Correct 4 ms 5408 KB Output is correct
25 Correct 4 ms 5408 KB Output is correct
26 Correct 5 ms 5408 KB Output is correct
27 Correct 3 ms 5408 KB Output is correct
28 Correct 3 ms 5408 KB Output is correct
29 Correct 5 ms 5408 KB Output is correct
30 Correct 4 ms 5408 KB Output is correct
31 Correct 5 ms 5408 KB Output is correct
32 Correct 5 ms 5408 KB Output is correct
33 Correct 8 ms 5632 KB Output is correct
34 Correct 7 ms 5632 KB Output is correct
35 Correct 11 ms 5676 KB Output is correct
36 Correct 4 ms 5676 KB Output is correct
37 Correct 11 ms 5936 KB Output is correct
38 Correct 12 ms 6256 KB Output is correct
39 Correct 11 ms 6392 KB Output is correct
40 Correct 11 ms 6660 KB Output is correct
41 Correct 11 ms 7048 KB Output is correct
42 Correct 8 ms 7184 KB Output is correct
43 Correct 8 ms 7396 KB Output is correct
44 Correct 8 ms 7604 KB Output is correct
45 Correct 18 ms 8196 KB Output is correct
46 Correct 13 ms 8284 KB Output is correct
47 Correct 19 ms 9004 KB Output is correct
48 Correct 10 ms 9004 KB Output is correct
49 Correct 10 ms 9004 KB Output is correct
50 Correct 7 ms 9004 KB Output is correct
51 Correct 24 ms 10172 KB Output is correct
52 Correct 24 ms 10592 KB Output is correct
53 Correct 14 ms 10592 KB Output is correct
54 Correct 4 ms 10592 KB Output is correct
55 Correct 5 ms 10592 KB Output is correct
56 Correct 13 ms 10784 KB Output is correct
57 Correct 5 ms 10784 KB Output is correct
58 Correct 11 ms 10784 KB Output is correct
59 Correct 14 ms 10784 KB Output is correct
60 Correct 11 ms 10876 KB Output is correct
61 Correct 11 ms 11084 KB Output is correct
62 Correct 17 ms 11972 KB Output is correct
63 Correct 50 ms 13660 KB Output is correct
64 Correct 57 ms 13924 KB Output is correct
65 Correct 70 ms 14152 KB Output is correct
66 Correct 163 ms 16460 KB Output is correct
67 Correct 99 ms 16504 KB Output is correct