답안 #48161

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

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

void connect(int px, int py, int qx, int qy, int cost) {
	int pos1 = lower_bound(vec.begin(), vec.end(), make_pair(px, py)) - vec.begin();
	int pos2 = lower_bound(vec.begin(), vec.end(), make_pair(qx, qy)) - vec.begin();
	X[pos1].push_back(make_pair(pos2, cost));
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> P[i]; G[A[i]].push_back(P[i]);
		if (M1[make_pair(A[i] % P[i], P[i])] == 0) {
			M1[make_pair(A[i] % P[i], P[i])] = 1;
			for (int j = A[i] % P[i]; j < N; j += P[i]) vec.emplace_back(make_pair(j, P[i]));
		}
	}
	for (int i = 0; i < N; i++) vec.push_back(make_pair(i, 0));
	sort(vec.begin(), vec.end());
	
	for (int i = 0; i < vec.size(); i++) {
		int pos = vec[i].first, state = vec[i].second;

		if (state == 0) {
			for (int j = 0; j < G[pos].size(); j++) connect(pos, 0, pos, G[pos][j], 0);
		}
		else {
			connect(pos, state, pos, 0, 0);
			if (pos - state >= 0) connect(pos, state, pos - state, state, 1);
			if (pos + state < N) connect(pos, state, pos + state, state, 1);
		}
	}
	for (int i = 0; i < vec.size(); i++) dist[i] = (1 << 30);
	int sx = lower_bound(vec.begin(), vec.end(), make_pair(A[1], 0)) - vec.begin();
	int gx = lower_bound(vec.begin(), vec.end(), make_pair(A[2], 0)) - vec.begin();
	dist[sx] = 0; Q.push(make_pair(dist[sx], sx));

	while (!Q.empty()) {
		int pos = Q.top().second; Q.pop();
		
		for (int i = 0; i < X[pos].size(); i++) {
			int to = X[pos][i].first, cost = X[pos][i].second;
			if (dist[to] > dist[pos] + cost) {
				dist[to] = dist[pos] + cost;
				Q.push(make_pair(dist[to], to));
			}
		}
	}
	int ans = dist[gx]; if (ans == (1 << 30)) ans = -1;
	cout << ans << endl;
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:31:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < vec.size(); i++) {
                  ~~^~~~~~~~~~~~
skyscraper.cpp:35:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < G[pos].size(); j++) connect(pos, 0, pos, G[pos][j], 0);
                    ~~^~~~~~~~~~~~~~~
skyscraper.cpp:43:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < vec.size(); i++) dist[i] = (1 << 30);
                  ~~^~~~~~~~~~~~
skyscraper.cpp:51:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < X[pos].size(); i++) {
                   ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 125432 KB Output is correct
2 Correct 101 ms 125548 KB Output is correct
3 Correct 101 ms 125548 KB Output is correct
4 Correct 100 ms 125548 KB Output is correct
5 Correct 105 ms 125672 KB Output is correct
6 Correct 104 ms 125672 KB Output is correct
7 Correct 102 ms 125672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 125692 KB Output is correct
2 Correct 103 ms 125728 KB Output is correct
3 Correct 103 ms 125756 KB Output is correct
4 Correct 104 ms 125756 KB Output is correct
5 Correct 103 ms 125756 KB Output is correct
6 Correct 102 ms 125756 KB Output is correct
7 Correct 102 ms 125796 KB Output is correct
8 Correct 105 ms 125796 KB Output is correct
9 Correct 104 ms 125820 KB Output is correct
10 Correct 104 ms 125824 KB Output is correct
11 Correct 112 ms 126136 KB Output is correct
12 Correct 105 ms 126136 KB Output is correct
13 Correct 105 ms 126136 KB Output is correct
14 Correct 113 ms 126300 KB Output is correct
15 Correct 110 ms 126340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 126340 KB Output is correct
2 Correct 105 ms 126340 KB Output is correct
3 Correct 106 ms 126340 KB Output is correct
4 Correct 105 ms 126340 KB Output is correct
5 Correct 101 ms 126340 KB Output is correct
6 Correct 106 ms 126340 KB Output is correct
7 Correct 101 ms 126340 KB Output is correct
8 Correct 100 ms 126340 KB Output is correct
9 Correct 105 ms 126340 KB Output is correct
10 Correct 103 ms 126340 KB Output is correct
11 Correct 110 ms 126340 KB Output is correct
12 Correct 106 ms 126340 KB Output is correct
13 Correct 105 ms 126340 KB Output is correct
14 Correct 110 ms 126340 KB Output is correct
15 Correct 111 ms 126340 KB Output is correct
16 Correct 107 ms 126340 KB Output is correct
17 Correct 122 ms 126716 KB Output is correct
18 Correct 139 ms 126716 KB Output is correct
19 Correct 110 ms 126716 KB Output is correct
20 Correct 106 ms 126716 KB Output is correct
21 Correct 106 ms 126716 KB Output is correct
22 Correct 108 ms 126716 KB Output is correct
23 Correct 108 ms 126716 KB Output is correct
24 Correct 114 ms 126716 KB Output is correct
25 Correct 110 ms 126716 KB Output is correct
26 Correct 109 ms 126716 KB Output is correct
27 Correct 109 ms 126716 KB Output is correct
28 Correct 123 ms 127352 KB Output is correct
29 Correct 158 ms 129452 KB Output is correct
30 Correct 120 ms 129452 KB Output is correct
31 Correct 130 ms 129452 KB Output is correct
32 Correct 125 ms 129452 KB Output is correct
33 Correct 230 ms 133000 KB Output is correct
34 Correct 220 ms 133000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 133000 KB Output is correct
2 Correct 100 ms 133000 KB Output is correct
3 Correct 100 ms 133000 KB Output is correct
4 Correct 101 ms 133000 KB Output is correct
5 Correct 103 ms 133000 KB Output is correct
6 Correct 100 ms 133000 KB Output is correct
7 Correct 105 ms 133000 KB Output is correct
8 Correct 101 ms 133000 KB Output is correct
9 Correct 107 ms 133000 KB Output is correct
10 Correct 104 ms 133000 KB Output is correct
11 Correct 108 ms 133000 KB Output is correct
12 Correct 107 ms 133000 KB Output is correct
13 Correct 104 ms 133000 KB Output is correct
14 Correct 111 ms 133000 KB Output is correct
15 Correct 109 ms 133000 KB Output is correct
16 Correct 130 ms 133000 KB Output is correct
17 Correct 119 ms 133000 KB Output is correct
18 Correct 111 ms 133000 KB Output is correct
19 Correct 109 ms 133000 KB Output is correct
20 Correct 105 ms 133000 KB Output is correct
21 Correct 108 ms 133000 KB Output is correct
22 Correct 106 ms 133000 KB Output is correct
23 Correct 112 ms 133000 KB Output is correct
24 Correct 120 ms 133000 KB Output is correct
25 Correct 115 ms 133000 KB Output is correct
26 Correct 113 ms 133000 KB Output is correct
27 Correct 111 ms 133000 KB Output is correct
28 Correct 127 ms 133000 KB Output is correct
29 Correct 163 ms 133000 KB Output is correct
30 Correct 121 ms 133000 KB Output is correct
31 Correct 134 ms 133000 KB Output is correct
32 Correct 125 ms 133000 KB Output is correct
33 Correct 229 ms 133000 KB Output is correct
34 Correct 232 ms 133036 KB Output is correct
35 Correct 243 ms 133832 KB Output is correct
36 Correct 141 ms 133832 KB Output is correct
37 Correct 332 ms 137448 KB Output is correct
38 Correct 324 ms 137596 KB Output is correct
39 Correct 331 ms 137596 KB Output is correct
40 Correct 324 ms 137596 KB Output is correct
41 Correct 344 ms 137596 KB Output is correct
42 Correct 125 ms 137596 KB Output is correct
43 Correct 124 ms 137596 KB Output is correct
44 Correct 122 ms 137596 KB Output is correct
45 Correct 698 ms 156220 KB Output is correct
46 Correct 677 ms 156384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 156384 KB Output is correct
2 Correct 102 ms 156384 KB Output is correct
3 Correct 102 ms 156384 KB Output is correct
4 Correct 102 ms 156384 KB Output is correct
5 Correct 100 ms 156384 KB Output is correct
6 Correct 102 ms 156384 KB Output is correct
7 Correct 101 ms 156384 KB Output is correct
8 Correct 101 ms 156384 KB Output is correct
9 Correct 101 ms 156384 KB Output is correct
10 Correct 109 ms 156384 KB Output is correct
11 Correct 108 ms 156384 KB Output is correct
12 Correct 103 ms 156384 KB Output is correct
13 Correct 103 ms 156384 KB Output is correct
14 Correct 115 ms 156384 KB Output is correct
15 Correct 114 ms 156384 KB Output is correct
16 Correct 108 ms 156384 KB Output is correct
17 Correct 118 ms 156384 KB Output is correct
18 Correct 106 ms 156384 KB Output is correct
19 Correct 106 ms 156384 KB Output is correct
20 Correct 105 ms 156384 KB Output is correct
21 Correct 104 ms 156384 KB Output is correct
22 Correct 114 ms 156384 KB Output is correct
23 Correct 109 ms 156384 KB Output is correct
24 Correct 114 ms 156384 KB Output is correct
25 Correct 110 ms 156384 KB Output is correct
26 Correct 108 ms 156384 KB Output is correct
27 Correct 113 ms 156384 KB Output is correct
28 Correct 131 ms 156384 KB Output is correct
29 Correct 171 ms 156384 KB Output is correct
30 Correct 121 ms 156384 KB Output is correct
31 Correct 131 ms 156384 KB Output is correct
32 Correct 122 ms 156384 KB Output is correct
33 Correct 237 ms 156384 KB Output is correct
34 Correct 223 ms 156384 KB Output is correct
35 Correct 236 ms 156384 KB Output is correct
36 Correct 129 ms 156384 KB Output is correct
37 Correct 323 ms 156384 KB Output is correct
38 Correct 319 ms 156384 KB Output is correct
39 Correct 320 ms 156384 KB Output is correct
40 Correct 329 ms 156384 KB Output is correct
41 Correct 317 ms 156384 KB Output is correct
42 Correct 126 ms 156384 KB Output is correct
43 Correct 131 ms 156384 KB Output is correct
44 Correct 121 ms 156384 KB Output is correct
45 Correct 669 ms 156512 KB Output is correct
46 Correct 656 ms 156512 KB Output is correct
47 Execution timed out 1096 ms 171644 KB Time limit exceeded
48 Halted 0 ms 0 KB -