답안 #771293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
771293 2023-07-02T19:30:48 Z IBory Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
134 ms 74172 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define pii pair<int, int>
using namespace std;

const int MAX = 30003;
vector<pii> G[MAX];
int D[MAX];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N, M, S, E;
	cin >> N >> M;
	map<pii, vector<int>> make;
	for (int i = 0; i < M; ++i) {
		int b, p;
		cin >> b >> p;
		if (i == 0) S = b;
		if (i == 1) E = b;
		make[{p, b % p}].push_back(b);
	}

	for (auto& [q, v] : make) {
		auto [p, init] = q;
		v.push_back(init);
		v.push_back(init + (N - 1 - init) / p * p);
		sort(v.begin(), v.end());
		for (int i = 1; i + 1 < v.size(); ++i) {
			int n = v[i] - p, d = 1;
			while (n >= v[i - 1]) {
				G[v[i]].emplace_back(n, d++);
				n -= p;
			}
			n = v[i] + p, d = 1;
			while (n <= v[i + 1]) {
				G[v[i]].emplace_back(n, d++);
				n += p;
			}
		}
	}

	memset(D, 0x3f, sizeof(D));
	priority_queue<pii, vector<pii>, greater<pii>> PQ; 
	PQ.emplace(D[S] = 0, S);
	while (!PQ.empty()) {
		auto [cd, cur] = PQ.top(); PQ.pop();
		if (cd > D[cur]) continue;
		if (cur == E) break;
		for (auto [next, nd] : G[cur]) {
			if (cd + nd >= D[next]) continue;
			PQ.emplace(D[next] = cd + nd, next);
		}
	}

	cout << (D[E] > 1E9 ? -1 : D[E]);
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:31:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for (int i = 1; i + 1 < v.size(); ++i) {
      |                   ~~~~~~^~~~~~~~~~
skyscraper.cpp:51:3: warning: 'E' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |   if (cur == E) break;
      |   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1236 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1364 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 2 ms 1364 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1364 KB Output is correct
15 Correct 2 ms 1364 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 2 ms 1492 KB Output is correct
25 Correct 2 ms 1364 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 2 ms 1492 KB Output is correct
29 Correct 3 ms 2004 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
31 Correct 2 ms 1620 KB Output is correct
32 Correct 2 ms 1492 KB Output is correct
33 Correct 5 ms 2900 KB Output is correct
34 Correct 4 ms 2788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 2 ms 1364 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 1 ms 1364 KB Output is correct
15 Correct 2 ms 1364 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 2 ms 1492 KB Output is correct
25 Correct 2 ms 1364 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 2 ms 1492 KB Output is correct
29 Correct 3 ms 2004 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
31 Correct 2 ms 1620 KB Output is correct
32 Correct 2 ms 1492 KB Output is correct
33 Correct 5 ms 2824 KB Output is correct
34 Correct 3 ms 2900 KB Output is correct
35 Correct 15 ms 4940 KB Output is correct
36 Correct 3 ms 1748 KB Output is correct
37 Correct 12 ms 5204 KB Output is correct
38 Correct 18 ms 6068 KB Output is correct
39 Correct 17 ms 5972 KB Output is correct
40 Correct 18 ms 6020 KB Output is correct
41 Correct 18 ms 6100 KB Output is correct
42 Correct 5 ms 1396 KB Output is correct
43 Correct 4 ms 1364 KB Output is correct
44 Correct 4 ms 1364 KB Output is correct
45 Correct 20 ms 9044 KB Output is correct
46 Correct 20 ms 9016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1108 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 1 ms 1108 KB Output is correct
14 Correct 2 ms 1364 KB Output is correct
15 Correct 1 ms 1364 KB Output is correct
16 Correct 1 ms 1236 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1108 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 2 ms 1492 KB Output is correct
25 Correct 2 ms 1364 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 2 ms 1492 KB Output is correct
29 Correct 3 ms 2004 KB Output is correct
30 Correct 1 ms 1364 KB Output is correct
31 Correct 2 ms 1620 KB Output is correct
32 Correct 1 ms 1492 KB Output is correct
33 Correct 5 ms 2900 KB Output is correct
34 Correct 3 ms 2900 KB Output is correct
35 Correct 15 ms 4948 KB Output is correct
36 Correct 3 ms 1748 KB Output is correct
37 Correct 13 ms 5152 KB Output is correct
38 Correct 18 ms 6100 KB Output is correct
39 Correct 17 ms 5996 KB Output is correct
40 Correct 18 ms 6084 KB Output is correct
41 Correct 18 ms 6100 KB Output is correct
42 Correct 4 ms 1364 KB Output is correct
43 Correct 4 ms 1304 KB Output is correct
44 Correct 4 ms 1364 KB Output is correct
45 Correct 22 ms 8976 KB Output is correct
46 Correct 20 ms 9016 KB Output is correct
47 Correct 24 ms 12896 KB Output is correct
48 Correct 15 ms 5888 KB Output is correct
49 Correct 13 ms 4948 KB Output is correct
50 Correct 10 ms 4180 KB Output is correct
51 Correct 25 ms 8516 KB Output is correct
52 Correct 26 ms 8848 KB Output is correct
53 Correct 18 ms 5436 KB Output is correct
54 Correct 2 ms 1620 KB Output is correct
55 Correct 2 ms 2004 KB Output is correct
56 Correct 7 ms 2132 KB Output is correct
57 Correct 8 ms 9828 KB Output is correct
58 Correct 6 ms 2256 KB Output is correct
59 Correct 7 ms 2512 KB Output is correct
60 Correct 7 ms 3248 KB Output is correct
61 Correct 7 ms 2768 KB Output is correct
62 Correct 22 ms 9304 KB Output is correct
63 Correct 60 ms 27912 KB Output is correct
64 Correct 63 ms 36368 KB Output is correct
65 Correct 80 ms 46364 KB Output is correct
66 Correct 134 ms 74124 KB Output is correct
67 Correct 107 ms 74172 KB Output is correct