Submission #48158

# Submission time Handle Problem Language Result Execution time Memory
48158 2018-05-10T11:39:59 Z E869120 Jakarta Skyscrapers (APIO15_skyscraper) C++14
22 / 100
1000 ms 90408 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
using namespace std;

long long N, M, A[30009], P[30009]; int cnt = 0;
vector<int>X[30009];
map<pair<long long, long long>, int>MM, MM2, dist; queue<pair<int, int>>Q;

void refresh(int to, int dst, int val) {
	if (to < 0 || to >= N) return;
	int F = dist[make_pair(to, dst)];
	if (F == 0) {
		dist[make_pair(to, dst)] = val;
		Q.push(make_pair(to, dst));
	}
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> P[i];
		long long G = A[i] % P[i]; MM2[make_pair(A[i], P[i])] = 1;
		if (MM[make_pair(G, P[i])] == 1) continue;
		MM[make_pair(G, P[i])] = 1;
		for (int j = G; j + P[i] < N; j++) {
			X[j].push_back(j + P[i]);
			X[j + P[i]].push_back(j);
		}
	}
	Q.push(make_pair(A[1], 0)); dist[make_pair(A[1], 0)] = 1;

	while (!Q.empty()) {
		pair<int, int> pos1 = Q.front(); Q.pop();
		int pos = pos1.first, state = pos1.second;

		if (state == 0) {
			for (int i = 0; i < X[pos].size(); i++) {
				int to = X[pos][i], dst = abs(pos - to); cnt++; if (MM2[make_pair(pos, dst)] == 0) continue;

				refresh(to, dst, dist[pos1] + 1);
				refresh(to, 0, dist[pos1] + 1);
			}
		}
		else {
			refresh(pos - state, state, dist[pos1] + 1);
			refresh(pos + state, state, dist[pos1] + 1);
			refresh(pos - state, 0, dist[pos1] + 1);
			refresh(pos + state, 0, dist[pos1] + 1);
		}
	}
	cout << dist[make_pair(A[2], 0)] - 1 << endl;
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:41:22: 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 2 ms 1016 KB Output is correct
2 Correct 2 ms 1124 KB Output is correct
3 Correct 3 ms 1220 KB Output is correct
4 Correct 2 ms 1220 KB Output is correct
5 Correct 2 ms 1220 KB Output is correct
6 Correct 2 ms 1220 KB Output is correct
7 Correct 2 ms 1220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1220 KB Output is correct
2 Correct 2 ms 1220 KB Output is correct
3 Correct 2 ms 1220 KB Output is correct
4 Correct 2 ms 1248 KB Output is correct
5 Correct 2 ms 1436 KB Output is correct
6 Correct 2 ms 1436 KB Output is correct
7 Correct 3 ms 1436 KB Output is correct
8 Correct 3 ms 1436 KB Output is correct
9 Correct 3 ms 1436 KB Output is correct
10 Correct 8 ms 1892 KB Output is correct
11 Correct 20 ms 2532 KB Output is correct
12 Correct 5 ms 2532 KB Output is correct
13 Correct 3 ms 2532 KB Output is correct
14 Correct 29 ms 2952 KB Output is correct
15 Correct 35 ms 2952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2952 KB Output is correct
2 Correct 2 ms 2952 KB Output is correct
3 Correct 2 ms 2952 KB Output is correct
4 Correct 2 ms 2952 KB Output is correct
5 Correct 2 ms 2952 KB Output is correct
6 Correct 3 ms 2952 KB Output is correct
7 Correct 2 ms 2952 KB Output is correct
8 Correct 2 ms 2952 KB Output is correct
9 Correct 3 ms 2952 KB Output is correct
10 Correct 10 ms 2952 KB Output is correct
11 Correct 21 ms 2952 KB Output is correct
12 Correct 4 ms 2952 KB Output is correct
13 Correct 3 ms 2952 KB Output is correct
14 Correct 26 ms 2952 KB Output is correct
15 Correct 26 ms 2952 KB Output is correct
16 Correct 5 ms 2952 KB Output is correct
17 Correct 247 ms 28156 KB Output is correct
18 Correct 23 ms 28156 KB Output is correct
19 Correct 18 ms 28156 KB Output is correct
20 Correct 6 ms 28156 KB Output is correct
21 Correct 6 ms 28156 KB Output is correct
22 Correct 20 ms 28156 KB Output is correct
23 Correct 234 ms 38860 KB Output is correct
24 Correct 599 ms 90376 KB Output is correct
25 Correct 455 ms 90376 KB Output is correct
26 Correct 93 ms 90376 KB Output is correct
27 Correct 135 ms 90376 KB Output is correct
28 Correct 460 ms 90376 KB Output is correct
29 Correct 379 ms 90376 KB Output is correct
30 Correct 81 ms 90376 KB Output is correct
31 Correct 244 ms 90376 KB Output is correct
32 Correct 177 ms 90376 KB Output is correct
33 Execution timed out 1056 ms 90376 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 90376 KB Output is correct
2 Correct 2 ms 90376 KB Output is correct
3 Correct 2 ms 90376 KB Output is correct
4 Correct 2 ms 90376 KB Output is correct
5 Correct 3 ms 90376 KB Output is correct
6 Correct 2 ms 90376 KB Output is correct
7 Correct 3 ms 90376 KB Output is correct
8 Correct 2 ms 90376 KB Output is correct
9 Correct 3 ms 90376 KB Output is correct
10 Correct 8 ms 90376 KB Output is correct
11 Correct 19 ms 90376 KB Output is correct
12 Correct 4 ms 90376 KB Output is correct
13 Correct 3 ms 90376 KB Output is correct
14 Correct 26 ms 90376 KB Output is correct
15 Correct 26 ms 90376 KB Output is correct
16 Correct 5 ms 90376 KB Output is correct
17 Correct 251 ms 90376 KB Output is correct
18 Correct 26 ms 90376 KB Output is correct
19 Correct 17 ms 90376 KB Output is correct
20 Correct 6 ms 90376 KB Output is correct
21 Correct 6 ms 90376 KB Output is correct
22 Correct 21 ms 90376 KB Output is correct
23 Correct 218 ms 90376 KB Output is correct
24 Correct 600 ms 90408 KB Output is correct
25 Correct 421 ms 90408 KB Output is correct
26 Correct 83 ms 90408 KB Output is correct
27 Correct 130 ms 90408 KB Output is correct
28 Correct 446 ms 90408 KB Output is correct
29 Correct 379 ms 90408 KB Output is correct
30 Correct 77 ms 90408 KB Output is correct
31 Correct 242 ms 90408 KB Output is correct
32 Correct 165 ms 90408 KB Output is correct
33 Execution timed out 1053 ms 90408 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 90408 KB Output is correct
2 Correct 2 ms 90408 KB Output is correct
3 Correct 2 ms 90408 KB Output is correct
4 Correct 2 ms 90408 KB Output is correct
5 Correct 2 ms 90408 KB Output is correct
6 Correct 2 ms 90408 KB Output is correct
7 Correct 2 ms 90408 KB Output is correct
8 Correct 2 ms 90408 KB Output is correct
9 Correct 3 ms 90408 KB Output is correct
10 Correct 8 ms 90408 KB Output is correct
11 Correct 19 ms 90408 KB Output is correct
12 Correct 4 ms 90408 KB Output is correct
13 Correct 3 ms 90408 KB Output is correct
14 Correct 27 ms 90408 KB Output is correct
15 Correct 26 ms 90408 KB Output is correct
16 Correct 6 ms 90408 KB Output is correct
17 Correct 261 ms 90408 KB Output is correct
18 Correct 23 ms 90408 KB Output is correct
19 Correct 18 ms 90408 KB Output is correct
20 Correct 6 ms 90408 KB Output is correct
21 Correct 5 ms 90408 KB Output is correct
22 Correct 19 ms 90408 KB Output is correct
23 Correct 222 ms 90408 KB Output is correct
24 Correct 594 ms 90408 KB Output is correct
25 Correct 428 ms 90408 KB Output is correct
26 Correct 86 ms 90408 KB Output is correct
27 Correct 129 ms 90408 KB Output is correct
28 Correct 467 ms 90408 KB Output is correct
29 Correct 396 ms 90408 KB Output is correct
30 Correct 83 ms 90408 KB Output is correct
31 Correct 239 ms 90408 KB Output is correct
32 Correct 171 ms 90408 KB Output is correct
33 Execution timed out 1085 ms 90408 KB Time limit exceeded
34 Halted 0 ms 0 KB -