답안 #48160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48160 2018-05-10T11:54:55 Z E869120 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 177252 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.push_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 100 ms 125560 KB Output is correct
2 Correct 115 ms 125700 KB Output is correct
3 Correct 110 ms 125700 KB Output is correct
4 Correct 102 ms 125700 KB Output is correct
5 Correct 103 ms 125700 KB Output is correct
6 Correct 103 ms 125744 KB Output is correct
7 Correct 102 ms 125744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 125744 KB Output is correct
2 Correct 107 ms 125756 KB Output is correct
3 Correct 102 ms 125780 KB Output is correct
4 Correct 101 ms 125804 KB Output is correct
5 Correct 100 ms 125804 KB Output is correct
6 Correct 102 ms 125804 KB Output is correct
7 Correct 100 ms 125804 KB Output is correct
8 Correct 102 ms 125820 KB Output is correct
9 Correct 103 ms 125820 KB Output is correct
10 Correct 109 ms 125948 KB Output is correct
11 Correct 107 ms 126076 KB Output is correct
12 Correct 106 ms 126076 KB Output is correct
13 Correct 105 ms 126076 KB Output is correct
14 Correct 107 ms 126244 KB Output is correct
15 Correct 106 ms 126244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 126244 KB Output is correct
2 Correct 105 ms 126244 KB Output is correct
3 Correct 102 ms 126244 KB Output is correct
4 Correct 103 ms 126244 KB Output is correct
5 Correct 101 ms 126244 KB Output is correct
6 Correct 103 ms 126244 KB Output is correct
7 Correct 107 ms 126244 KB Output is correct
8 Correct 119 ms 126244 KB Output is correct
9 Correct 107 ms 126244 KB Output is correct
10 Correct 109 ms 126244 KB Output is correct
11 Correct 110 ms 126244 KB Output is correct
12 Correct 105 ms 126244 KB Output is correct
13 Correct 115 ms 126244 KB Output is correct
14 Correct 112 ms 126244 KB Output is correct
15 Correct 111 ms 126244 KB Output is correct
16 Correct 107 ms 126244 KB Output is correct
17 Correct 120 ms 126844 KB Output is correct
18 Correct 112 ms 126844 KB Output is correct
19 Correct 110 ms 126844 KB Output is correct
20 Correct 104 ms 126844 KB Output is correct
21 Correct 106 ms 126844 KB Output is correct
22 Correct 110 ms 126844 KB Output is correct
23 Correct 110 ms 126844 KB Output is correct
24 Correct 116 ms 126844 KB Output is correct
25 Correct 114 ms 126844 KB Output is correct
26 Correct 111 ms 126844 KB Output is correct
27 Correct 110 ms 126844 KB Output is correct
28 Correct 125 ms 127480 KB Output is correct
29 Correct 160 ms 129372 KB Output is correct
30 Correct 119 ms 129372 KB Output is correct
31 Correct 136 ms 129372 KB Output is correct
32 Correct 123 ms 129372 KB Output is correct
33 Correct 225 ms 133060 KB Output is correct
34 Correct 231 ms 133060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 133060 KB Output is correct
2 Correct 104 ms 133060 KB Output is correct
3 Correct 102 ms 133060 KB Output is correct
4 Correct 102 ms 133060 KB Output is correct
5 Correct 102 ms 133060 KB Output is correct
6 Correct 100 ms 133060 KB Output is correct
7 Correct 101 ms 133060 KB Output is correct
8 Correct 102 ms 133060 KB Output is correct
9 Correct 102 ms 133060 KB Output is correct
10 Correct 103 ms 133060 KB Output is correct
11 Correct 106 ms 133060 KB Output is correct
12 Correct 100 ms 133060 KB Output is correct
13 Correct 105 ms 133060 KB Output is correct
14 Correct 117 ms 133060 KB Output is correct
15 Correct 108 ms 133060 KB Output is correct
16 Correct 105 ms 133060 KB Output is correct
17 Correct 115 ms 133060 KB Output is correct
18 Correct 109 ms 133060 KB Output is correct
19 Correct 107 ms 133060 KB Output is correct
20 Correct 105 ms 133060 KB Output is correct
21 Correct 104 ms 133060 KB Output is correct
22 Correct 107 ms 133060 KB Output is correct
23 Correct 108 ms 133060 KB Output is correct
24 Correct 115 ms 133060 KB Output is correct
25 Correct 115 ms 133060 KB Output is correct
26 Correct 109 ms 133060 KB Output is correct
27 Correct 110 ms 133060 KB Output is correct
28 Correct 129 ms 133060 KB Output is correct
29 Correct 161 ms 133060 KB Output is correct
30 Correct 119 ms 133060 KB Output is correct
31 Correct 132 ms 133060 KB Output is correct
32 Correct 127 ms 133060 KB Output is correct
33 Correct 225 ms 133084 KB Output is correct
34 Correct 222 ms 133084 KB Output is correct
35 Correct 241 ms 134100 KB Output is correct
36 Correct 122 ms 134100 KB Output is correct
37 Correct 329 ms 138068 KB Output is correct
38 Correct 323 ms 138364 KB Output is correct
39 Correct 321 ms 138540 KB Output is correct
40 Correct 325 ms 138776 KB Output is correct
41 Correct 323 ms 139036 KB Output is correct
42 Correct 129 ms 139036 KB Output is correct
43 Correct 126 ms 139036 KB Output is correct
44 Correct 122 ms 139036 KB Output is correct
45 Correct 666 ms 158768 KB Output is correct
46 Correct 676 ms 159012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 103 ms 159012 KB Output is correct
2 Correct 103 ms 159012 KB Output is correct
3 Correct 103 ms 159012 KB Output is correct
4 Correct 108 ms 159012 KB Output is correct
5 Correct 109 ms 159012 KB Output is correct
6 Correct 103 ms 159012 KB Output is correct
7 Correct 100 ms 159012 KB Output is correct
8 Correct 105 ms 159012 KB Output is correct
9 Correct 116 ms 159012 KB Output is correct
10 Correct 103 ms 159012 KB Output is correct
11 Correct 107 ms 159012 KB Output is correct
12 Correct 101 ms 159012 KB Output is correct
13 Correct 101 ms 159012 KB Output is correct
14 Correct 106 ms 159012 KB Output is correct
15 Correct 108 ms 159012 KB Output is correct
16 Correct 113 ms 159012 KB Output is correct
17 Correct 117 ms 159012 KB Output is correct
18 Correct 124 ms 159012 KB Output is correct
19 Correct 104 ms 159012 KB Output is correct
20 Correct 106 ms 159012 KB Output is correct
21 Correct 107 ms 159012 KB Output is correct
22 Correct 107 ms 159012 KB Output is correct
23 Correct 111 ms 159012 KB Output is correct
24 Correct 116 ms 159012 KB Output is correct
25 Correct 113 ms 159012 KB Output is correct
26 Correct 111 ms 159012 KB Output is correct
27 Correct 110 ms 159012 KB Output is correct
28 Correct 124 ms 159012 KB Output is correct
29 Correct 168 ms 159012 KB Output is correct
30 Correct 117 ms 159012 KB Output is correct
31 Correct 135 ms 159012 KB Output is correct
32 Correct 125 ms 159012 KB Output is correct
33 Correct 232 ms 159012 KB Output is correct
34 Correct 225 ms 159012 KB Output is correct
35 Correct 248 ms 159012 KB Output is correct
36 Correct 124 ms 159012 KB Output is correct
37 Correct 354 ms 159012 KB Output is correct
38 Correct 319 ms 159012 KB Output is correct
39 Correct 319 ms 159012 KB Output is correct
40 Correct 326 ms 159012 KB Output is correct
41 Correct 329 ms 159012 KB Output is correct
42 Correct 128 ms 159012 KB Output is correct
43 Correct 127 ms 159012 KB Output is correct
44 Correct 124 ms 159012 KB Output is correct
45 Correct 671 ms 161388 KB Output is correct
46 Correct 690 ms 161488 KB Output is correct
47 Execution timed out 1085 ms 177252 KB Time limit exceeded
48 Halted 0 ms 0 KB -