답안 #48174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48174 2018-05-10T12:44:24 Z E869120 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 189304 KB
#include <iostream>
#include <queue>
#include <vector>
#include <map>
using namespace std;

int N, M, A[30009], P[30009]; vector<int>G[30009], dist[30009]; vector<vector<pair<int, int>>> X[30009];
map<pair<int, int>, int>M1; queue<pair<int, int>>Q;

void connect(int px, int py, int qx, int qy) {
	X[px][py].push_back(make_pair(qx, qy));
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) G[0].push_back(i);
	X[0].resize(G[0].size());
	dist[0].resize(G[0].size(), (1 << 30));
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> P[i];
		int J = M1[make_pair(A[i] % P[i], P[i])];
		if (J == 0) {
			M1[make_pair(A[i] % P[i], P[i])] = i; J = i;
			for (int j = A[i] % P[i]; j < N; j += P[i]) G[i].push_back(j);
			X[i].resize(G[i].size());
			dist[i].resize(G[i].size(), (1 << 30));
			for (int j = 0; j < (int)G[i].size() - 1; j++) {
				connect(i, j, i, j + 1);
				connect(i, j + 1, i, j);
				connect(i, j, 0, G[i][j + 1]);
				connect(i, j + 1, 0, G[i][j]);
			}
		}
		int pos1 = lower_bound(G[J].begin(), G[J].end(), A[i]) - G[J].begin();
		if (A[i] + P[i] < N) connect(0, A[i], 0, A[i] + P[i]);
		if (A[i] - P[i] >= 0) connect(0, A[i], 0, A[i] - P[i]);
		if (pos1 >= 1) connect(0, A[i], J, pos1 - 1);
		if (pos1 + 1 < G[J].size()) connect(0, A[i], J, pos1 + 1);
	}
	dist[0][A[1]] = 0; Q.push(make_pair(0, A[1]));

	while (!Q.empty()) {
		int pos1 = Q.front().first, pos2 = Q.front().second; Q.pop();
		for (int i = 0; i < X[pos1][pos2].size(); i++) {
			int to1 = X[pos1][pos2][i].first, to2 = X[pos1][pos2][i].second;
			if (dist[to1][to2] > dist[pos1][pos2] + 1) {
				dist[to1][to2] = dist[pos1][pos2] + 1;
				Q.push(make_pair(to1, to2));
			}
		}
	}
	if (dist[0][A[2]] == (1 << 30)) dist[0][A[2]] = -1;
	cout << dist[0][A[2]] << endl;
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:38:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (pos1 + 1 < G[J].size()) connect(0, A[i], J, pos1 + 1);
       ~~~~~~~~~^~~~~~~~~~~~~
skyscraper.cpp:44:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < X[pos1][pos2].size(); i++) {
                   ~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 3 ms 2536 KB Output is correct
3 Correct 3 ms 2536 KB Output is correct
4 Correct 3 ms 2536 KB Output is correct
5 Correct 4 ms 2636 KB Output is correct
6 Correct 3 ms 2696 KB Output is correct
7 Correct 3 ms 2696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2696 KB Output is correct
2 Correct 3 ms 2696 KB Output is correct
3 Correct 3 ms 2696 KB Output is correct
4 Correct 3 ms 2696 KB Output is correct
5 Correct 3 ms 2696 KB Output is correct
6 Correct 3 ms 2696 KB Output is correct
7 Correct 3 ms 2696 KB Output is correct
8 Correct 3 ms 2696 KB Output is correct
9 Correct 3 ms 2716 KB Output is correct
10 Correct 4 ms 2788 KB Output is correct
11 Correct 7 ms 3196 KB Output is correct
12 Correct 4 ms 3196 KB Output is correct
13 Correct 4 ms 3196 KB Output is correct
14 Correct 7 ms 3472 KB Output is correct
15 Correct 7 ms 3472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3472 KB Output is correct
2 Correct 3 ms 3472 KB Output is correct
3 Correct 4 ms 3472 KB Output is correct
4 Correct 3 ms 3472 KB Output is correct
5 Correct 3 ms 3472 KB Output is correct
6 Correct 4 ms 3472 KB Output is correct
7 Correct 4 ms 3472 KB Output is correct
8 Correct 4 ms 3472 KB Output is correct
9 Correct 3 ms 3472 KB Output is correct
10 Correct 4 ms 3472 KB Output is correct
11 Correct 7 ms 3472 KB Output is correct
12 Correct 6 ms 3472 KB Output is correct
13 Correct 5 ms 3472 KB Output is correct
14 Correct 8 ms 3472 KB Output is correct
15 Correct 8 ms 3472 KB Output is correct
16 Correct 6 ms 3472 KB Output is correct
17 Correct 10 ms 4092 KB Output is correct
18 Correct 6 ms 4092 KB Output is correct
19 Correct 5 ms 4092 KB Output is correct
20 Correct 5 ms 4092 KB Output is correct
21 Correct 5 ms 4092 KB Output is correct
22 Correct 6 ms 4092 KB Output is correct
23 Correct 7 ms 4092 KB Output is correct
24 Correct 12 ms 4092 KB Output is correct
25 Correct 8 ms 4092 KB Output is correct
26 Correct 7 ms 4092 KB Output is correct
27 Correct 6 ms 4092 KB Output is correct
28 Correct 12 ms 4732 KB Output is correct
29 Correct 22 ms 7712 KB Output is correct
30 Correct 8 ms 7712 KB Output is correct
31 Correct 13 ms 7712 KB Output is correct
32 Correct 10 ms 7712 KB Output is correct
33 Correct 41 ms 12540 KB Output is correct
34 Correct 41 ms 12540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12540 KB Output is correct
2 Correct 3 ms 12540 KB Output is correct
3 Correct 3 ms 12540 KB Output is correct
4 Correct 3 ms 12540 KB Output is correct
5 Correct 3 ms 12540 KB Output is correct
6 Correct 3 ms 12540 KB Output is correct
7 Correct 4 ms 12540 KB Output is correct
8 Correct 3 ms 12540 KB Output is correct
9 Correct 3 ms 12540 KB Output is correct
10 Correct 4 ms 12540 KB Output is correct
11 Correct 7 ms 12540 KB Output is correct
12 Correct 5 ms 12540 KB Output is correct
13 Correct 4 ms 12540 KB Output is correct
14 Correct 7 ms 12540 KB Output is correct
15 Correct 7 ms 12540 KB Output is correct
16 Correct 5 ms 12540 KB Output is correct
17 Correct 11 ms 12540 KB Output is correct
18 Correct 6 ms 12540 KB Output is correct
19 Correct 5 ms 12540 KB Output is correct
20 Correct 5 ms 12540 KB Output is correct
21 Correct 5 ms 12540 KB Output is correct
22 Correct 5 ms 12540 KB Output is correct
23 Correct 6 ms 12540 KB Output is correct
24 Correct 9 ms 12540 KB Output is correct
25 Correct 8 ms 12540 KB Output is correct
26 Correct 7 ms 12540 KB Output is correct
27 Correct 6 ms 12540 KB Output is correct
28 Correct 11 ms 12540 KB Output is correct
29 Correct 21 ms 12540 KB Output is correct
30 Correct 8 ms 12540 KB Output is correct
31 Correct 13 ms 12540 KB Output is correct
32 Correct 11 ms 12540 KB Output is correct
33 Correct 43 ms 12768 KB Output is correct
34 Correct 41 ms 12768 KB Output is correct
35 Correct 107 ms 13672 KB Output is correct
36 Correct 14 ms 13672 KB Output is correct
37 Correct 110 ms 19052 KB Output is correct
38 Correct 132 ms 19160 KB Output is correct
39 Correct 124 ms 19160 KB Output is correct
40 Correct 123 ms 19160 KB Output is correct
41 Correct 129 ms 19160 KB Output is correct
42 Correct 24 ms 19160 KB Output is correct
43 Correct 24 ms 19160 KB Output is correct
44 Correct 23 ms 19160 KB Output is correct
45 Correct 286 ms 44772 KB Output is correct
46 Correct 286 ms 44780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 44780 KB Output is correct
2 Correct 3 ms 44780 KB Output is correct
3 Correct 3 ms 44780 KB Output is correct
4 Correct 3 ms 44780 KB Output is correct
5 Correct 3 ms 44780 KB Output is correct
6 Correct 3 ms 44780 KB Output is correct
7 Correct 3 ms 44780 KB Output is correct
8 Correct 3 ms 44780 KB Output is correct
9 Correct 3 ms 44780 KB Output is correct
10 Correct 4 ms 44780 KB Output is correct
11 Correct 6 ms 44780 KB Output is correct
12 Correct 4 ms 44780 KB Output is correct
13 Correct 4 ms 44780 KB Output is correct
14 Correct 7 ms 44780 KB Output is correct
15 Correct 7 ms 44780 KB Output is correct
16 Correct 5 ms 44780 KB Output is correct
17 Correct 10 ms 44780 KB Output is correct
18 Correct 6 ms 44780 KB Output is correct
19 Correct 5 ms 44780 KB Output is correct
20 Correct 6 ms 44780 KB Output is correct
21 Correct 5 ms 44780 KB Output is correct
22 Correct 7 ms 44780 KB Output is correct
23 Correct 6 ms 44780 KB Output is correct
24 Correct 9 ms 44780 KB Output is correct
25 Correct 9 ms 44780 KB Output is correct
26 Correct 7 ms 44780 KB Output is correct
27 Correct 7 ms 44780 KB Output is correct
28 Correct 12 ms 44780 KB Output is correct
29 Correct 22 ms 44780 KB Output is correct
30 Correct 8 ms 44780 KB Output is correct
31 Correct 13 ms 44780 KB Output is correct
32 Correct 11 ms 44780 KB Output is correct
33 Correct 44 ms 44780 KB Output is correct
34 Correct 42 ms 44780 KB Output is correct
35 Correct 83 ms 44780 KB Output is correct
36 Correct 14 ms 44780 KB Output is correct
37 Correct 112 ms 44780 KB Output is correct
38 Correct 127 ms 44780 KB Output is correct
39 Correct 125 ms 44780 KB Output is correct
40 Correct 130 ms 44780 KB Output is correct
41 Correct 124 ms 44780 KB Output is correct
42 Correct 24 ms 44780 KB Output is correct
43 Correct 24 ms 44780 KB Output is correct
44 Correct 24 ms 44780 KB Output is correct
45 Correct 297 ms 44832 KB Output is correct
46 Correct 280 ms 44832 KB Output is correct
47 Correct 410 ms 65184 KB Output is correct
48 Correct 121 ms 65184 KB Output is correct
49 Correct 89 ms 65184 KB Output is correct
50 Correct 64 ms 65184 KB Output is correct
51 Correct 195 ms 65184 KB Output is correct
52 Correct 201 ms 65184 KB Output is correct
53 Correct 74 ms 65184 KB Output is correct
54 Correct 11 ms 65184 KB Output is correct
55 Correct 17 ms 65184 KB Output is correct
56 Correct 42 ms 65184 KB Output is correct
57 Correct 153 ms 65184 KB Output is correct
58 Correct 34 ms 65184 KB Output is correct
59 Correct 49 ms 65184 KB Output is correct
60 Correct 56 ms 65184 KB Output is correct
61 Correct 56 ms 65184 KB Output is correct
62 Correct 219 ms 65184 KB Output is correct
63 Execution timed out 1078 ms 189304 KB Time limit exceeded
64 Halted 0 ms 0 KB -