Submission #48164

# Submission time Handle Problem Language Result Execution time Memory
48164 2018-05-10T12:03:05 Z E869120 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 103480 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[7400009], sz; pair<int, int>vec[2400009];
vector<pair<int, int>>X[2400009]; 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, vec + sz, make_pair(px, py)) - vec;
	int pos2 = lower_bound(vec, vec + sz, make_pair(qx, qy)) - vec;
	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[sz] = make_pair(j, P[i]); sz++; }
		}
	}
	for (int i = 0; i < N; i++) { vec[sz] = make_pair(i, 0); sz++; }
	sort(vec, vec + sz);
	
	for (int i = 0; i < sz; 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 < sz; i++) dist[i] = (1 << 30);
	int sx = lower_bound(vec, vec + sz, make_pair(A[1], 0)) - vec;
	int gx = lower_bound(vec, vec + sz, make_pair(A[2], 0)) - vec;
	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:36: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:52:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < X[pos].size(); i++) {
                   ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 57468 KB Output is correct
2 Correct 46 ms 57576 KB Output is correct
3 Correct 47 ms 57576 KB Output is correct
4 Correct 47 ms 57576 KB Output is correct
5 Correct 46 ms 57576 KB Output is correct
6 Correct 47 ms 57600 KB Output is correct
7 Correct 47 ms 57600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 57608 KB Output is correct
2 Correct 48 ms 57608 KB Output is correct
3 Correct 47 ms 57624 KB Output is correct
4 Correct 49 ms 57672 KB Output is correct
5 Correct 48 ms 57672 KB Output is correct
6 Correct 48 ms 57672 KB Output is correct
7 Correct 47 ms 57672 KB Output is correct
8 Correct 50 ms 57676 KB Output is correct
9 Correct 47 ms 57676 KB Output is correct
10 Correct 48 ms 57784 KB Output is correct
11 Correct 56 ms 58008 KB Output is correct
12 Correct 47 ms 58008 KB Output is correct
13 Correct 49 ms 58008 KB Output is correct
14 Correct 54 ms 58092 KB Output is correct
15 Correct 53 ms 58220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 58220 KB Output is correct
2 Correct 49 ms 58220 KB Output is correct
3 Correct 46 ms 58220 KB Output is correct
4 Correct 47 ms 58220 KB Output is correct
5 Correct 48 ms 58220 KB Output is correct
6 Correct 50 ms 58220 KB Output is correct
7 Correct 46 ms 58220 KB Output is correct
8 Correct 47 ms 58220 KB Output is correct
9 Correct 47 ms 58220 KB Output is correct
10 Correct 51 ms 58220 KB Output is correct
11 Correct 57 ms 58220 KB Output is correct
12 Correct 48 ms 58220 KB Output is correct
13 Correct 48 ms 58220 KB Output is correct
14 Correct 54 ms 58220 KB Output is correct
15 Correct 62 ms 58220 KB Output is correct
16 Correct 54 ms 58220 KB Output is correct
17 Correct 62 ms 58620 KB Output is correct
18 Correct 53 ms 58620 KB Output is correct
19 Correct 64 ms 58620 KB Output is correct
20 Correct 51 ms 58620 KB Output is correct
21 Correct 49 ms 58620 KB Output is correct
22 Correct 52 ms 58620 KB Output is correct
23 Correct 59 ms 58620 KB Output is correct
24 Correct 62 ms 58620 KB Output is correct
25 Correct 56 ms 58620 KB Output is correct
26 Correct 55 ms 58620 KB Output is correct
27 Correct 57 ms 58620 KB Output is correct
28 Correct 68 ms 59260 KB Output is correct
29 Correct 101 ms 61308 KB Output is correct
30 Correct 63 ms 61308 KB Output is correct
31 Correct 76 ms 61308 KB Output is correct
32 Correct 68 ms 61308 KB Output is correct
33 Correct 167 ms 64864 KB Output is correct
34 Correct 163 ms 64892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 64892 KB Output is correct
2 Correct 49 ms 64892 KB Output is correct
3 Correct 49 ms 64892 KB Output is correct
4 Correct 49 ms 64892 KB Output is correct
5 Correct 49 ms 64892 KB Output is correct
6 Correct 49 ms 64892 KB Output is correct
7 Correct 48 ms 64892 KB Output is correct
8 Correct 49 ms 64892 KB Output is correct
9 Correct 50 ms 64892 KB Output is correct
10 Correct 50 ms 64892 KB Output is correct
11 Correct 54 ms 64892 KB Output is correct
12 Correct 49 ms 64892 KB Output is correct
13 Correct 49 ms 64892 KB Output is correct
14 Correct 55 ms 64892 KB Output is correct
15 Correct 55 ms 64892 KB Output is correct
16 Correct 52 ms 64892 KB Output is correct
17 Correct 63 ms 64892 KB Output is correct
18 Correct 55 ms 64892 KB Output is correct
19 Correct 53 ms 64892 KB Output is correct
20 Correct 51 ms 64892 KB Output is correct
21 Correct 52 ms 64892 KB Output is correct
22 Correct 54 ms 64892 KB Output is correct
23 Correct 56 ms 64892 KB Output is correct
24 Correct 62 ms 64892 KB Output is correct
25 Correct 58 ms 64892 KB Output is correct
26 Correct 56 ms 64892 KB Output is correct
27 Correct 56 ms 64892 KB Output is correct
28 Correct 68 ms 64892 KB Output is correct
29 Correct 102 ms 64892 KB Output is correct
30 Correct 63 ms 64892 KB Output is correct
31 Correct 78 ms 64892 KB Output is correct
32 Correct 67 ms 64892 KB Output is correct
33 Correct 161 ms 64892 KB Output is correct
34 Correct 161 ms 64904 KB Output is correct
35 Correct 178 ms 65532 KB Output is correct
36 Correct 68 ms 65532 KB Output is correct
37 Correct 266 ms 69320 KB Output is correct
38 Correct 256 ms 69372 KB Output is correct
39 Correct 254 ms 69372 KB Output is correct
40 Correct 273 ms 69536 KB Output is correct
41 Correct 262 ms 69536 KB Output is correct
42 Correct 73 ms 69536 KB Output is correct
43 Correct 72 ms 69536 KB Output is correct
44 Correct 68 ms 69536 KB Output is correct
45 Correct 593 ms 88112 KB Output is correct
46 Correct 630 ms 88112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 88112 KB Output is correct
2 Correct 50 ms 88112 KB Output is correct
3 Correct 47 ms 88112 KB Output is correct
4 Correct 49 ms 88112 KB Output is correct
5 Correct 48 ms 88112 KB Output is correct
6 Correct 47 ms 88112 KB Output is correct
7 Correct 47 ms 88112 KB Output is correct
8 Correct 50 ms 88112 KB Output is correct
9 Correct 49 ms 88112 KB Output is correct
10 Correct 50 ms 88112 KB Output is correct
11 Correct 52 ms 88112 KB Output is correct
12 Correct 49 ms 88112 KB Output is correct
13 Correct 48 ms 88112 KB Output is correct
14 Correct 55 ms 88112 KB Output is correct
15 Correct 56 ms 88112 KB Output is correct
16 Correct 52 ms 88112 KB Output is correct
17 Correct 62 ms 88112 KB Output is correct
18 Correct 58 ms 88112 KB Output is correct
19 Correct 54 ms 88112 KB Output is correct
20 Correct 52 ms 88112 KB Output is correct
21 Correct 50 ms 88112 KB Output is correct
22 Correct 52 ms 88112 KB Output is correct
23 Correct 55 ms 88112 KB Output is correct
24 Correct 62 ms 88112 KB Output is correct
25 Correct 58 ms 88112 KB Output is correct
26 Correct 56 ms 88112 KB Output is correct
27 Correct 55 ms 88112 KB Output is correct
28 Correct 69 ms 88112 KB Output is correct
29 Correct 105 ms 88112 KB Output is correct
30 Correct 63 ms 88112 KB Output is correct
31 Correct 80 ms 88112 KB Output is correct
32 Correct 68 ms 88112 KB Output is correct
33 Correct 166 ms 88112 KB Output is correct
34 Correct 162 ms 88112 KB Output is correct
35 Correct 177 ms 88112 KB Output is correct
36 Correct 70 ms 88112 KB Output is correct
37 Correct 274 ms 88112 KB Output is correct
38 Correct 260 ms 88112 KB Output is correct
39 Correct 257 ms 88112 KB Output is correct
40 Correct 262 ms 88112 KB Output is correct
41 Correct 260 ms 88112 KB Output is correct
42 Correct 78 ms 88112 KB Output is correct
43 Correct 71 ms 88112 KB Output is correct
44 Correct 66 ms 88112 KB Output is correct
45 Correct 590 ms 88188 KB Output is correct
46 Correct 585 ms 88188 KB Output is correct
47 Execution timed out 1031 ms 103480 KB Time limit exceeded
48 Halted 0 ms 0 KB -