답안 #110977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110977 2019-05-13T12:55:49 Z square1001 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 154512 KB
#include <set>
#include <deque>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> B(M), P(M);
	for(int i = 0; i < M; ++i) {
		cin >> B[i] >> P[i];
	}
	int sum = 0;
	set<pair<int, int> > s;
	for(int i = 0; i < M; ++i) {
		pair<int, int> u = make_pair(B[i] % P[i], P[i]);
		if(s.find(u) == s.end()) {
			sum += ((N - 1) - B[i] % P[i] + P[i]) / P[i];
			s.insert(u);
		}
	}
	vector<vector<int> > G(N + sum);
	unordered_map<int, int> d;
	int cnt = N;
	for(pair<int, int> i : s) {
		for(int j = i.first; j < N; j += i.second) {
			d[i.second * N + j] = cnt;
			G[cnt].push_back(j);
			if(j != i.first) {
				G[cnt].push_back(cnt - 1);
				G[cnt - 1].push_back(cnt);
			}
			++cnt;
		}
	}
	for(int i = 0; i < M; ++i) {
		G[B[i]].push_back(d[P[i] * N + B[i]]);
	}
	vector<int> dist(N + sum, -1); dist[B[0]] = 0;
	deque<int> que; que.push_back(B[0]);
	while(!que.empty()) {
		int u = que.front(); que.pop_front();
		for(int i : G[u]) {
			if(dist[i] != -1) continue;
			if(u < N || i < N) dist[i] = dist[u], que.push_front(i);
			else dist[i] = dist[u] + 1, que.push_back(i);
		}
	}
	cout << dist[B[1]] << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
7 Correct 3 ms 356 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 5 ms 896 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 5 ms 1024 KB Output is correct
15 Correct 8 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 6 ms 896 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 5 ms 1024 KB Output is correct
15 Correct 5 ms 1024 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 9 ms 1920 KB Output is correct
18 Correct 8 ms 1152 KB Output is correct
19 Correct 4 ms 896 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 5 ms 996 KB Output is correct
23 Correct 6 ms 1280 KB Output is correct
24 Correct 9 ms 1792 KB Output is correct
25 Correct 7 ms 1408 KB Output is correct
26 Correct 6 ms 1280 KB Output is correct
27 Correct 1 ms 1152 KB Output is correct
28 Correct 21 ms 2816 KB Output is correct
29 Correct 40 ms 6792 KB Output is correct
30 Correct 10 ms 2176 KB Output is correct
31 Correct 21 ms 3760 KB Output is correct
32 Correct 12 ms 2816 KB Output is correct
33 Correct 93 ms 13116 KB Output is correct
34 Correct 89 ms 12988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 4 ms 896 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 8 ms 1152 KB Output is correct
15 Correct 6 ms 1024 KB Output is correct
16 Correct 4 ms 768 KB Output is correct
17 Correct 12 ms 2048 KB Output is correct
18 Correct 6 ms 1152 KB Output is correct
19 Correct 6 ms 896 KB Output is correct
20 Correct 4 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 5 ms 1024 KB Output is correct
23 Correct 7 ms 1152 KB Output is correct
24 Correct 9 ms 1920 KB Output is correct
25 Correct 7 ms 1408 KB Output is correct
26 Correct 6 ms 1152 KB Output is correct
27 Correct 6 ms 1152 KB Output is correct
28 Correct 12 ms 2816 KB Output is correct
29 Correct 28 ms 6792 KB Output is correct
30 Correct 9 ms 2176 KB Output is correct
31 Correct 14 ms 3888 KB Output is correct
32 Correct 9 ms 2688 KB Output is correct
33 Correct 64 ms 12988 KB Output is correct
34 Correct 68 ms 13012 KB Output is correct
35 Correct 125 ms 12300 KB Output is correct
36 Correct 13 ms 2560 KB Output is correct
37 Correct 184 ms 19008 KB Output is correct
38 Correct 180 ms 18752 KB Output is correct
39 Correct 190 ms 18816 KB Output is correct
40 Correct 164 ms 18748 KB Output is correct
41 Correct 176 ms 18620 KB Output is correct
42 Correct 21 ms 1784 KB Output is correct
43 Correct 29 ms 1756 KB Output is correct
44 Correct 21 ms 1152 KB Output is correct
45 Correct 464 ms 52848 KB Output is correct
46 Correct 502 ms 52856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 4 ms 512 KB Output is correct
11 Correct 7 ms 896 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 7 ms 1024 KB Output is correct
15 Correct 7 ms 1024 KB Output is correct
16 Correct 6 ms 768 KB Output is correct
17 Correct 12 ms 2140 KB Output is correct
18 Correct 7 ms 1152 KB Output is correct
19 Correct 5 ms 896 KB Output is correct
20 Correct 5 ms 640 KB Output is correct
21 Correct 4 ms 640 KB Output is correct
22 Correct 6 ms 1024 KB Output is correct
23 Correct 6 ms 1152 KB Output is correct
24 Correct 10 ms 1792 KB Output is correct
25 Correct 9 ms 1280 KB Output is correct
26 Correct 7 ms 1152 KB Output is correct
27 Correct 5 ms 1152 KB Output is correct
28 Correct 14 ms 2816 KB Output is correct
29 Correct 51 ms 6792 KB Output is correct
30 Correct 12 ms 2176 KB Output is correct
31 Correct 16 ms 3760 KB Output is correct
32 Correct 11 ms 2688 KB Output is correct
33 Correct 84 ms 13148 KB Output is correct
34 Correct 80 ms 12988 KB Output is correct
35 Correct 145 ms 12348 KB Output is correct
36 Correct 17 ms 2560 KB Output is correct
37 Correct 198 ms 18932 KB Output is correct
38 Correct 205 ms 18620 KB Output is correct
39 Correct 217 ms 18876 KB Output is correct
40 Correct 239 ms 18748 KB Output is correct
41 Correct 242 ms 18752 KB Output is correct
42 Correct 23 ms 1784 KB Output is correct
43 Correct 21 ms 1792 KB Output is correct
44 Correct 29 ms 1224 KB Output is correct
45 Correct 467 ms 52856 KB Output is correct
46 Correct 458 ms 52916 KB Output is correct
47 Correct 938 ms 76144 KB Output is correct
48 Correct 304 ms 27404 KB Output is correct
49 Correct 167 ms 17460 KB Output is correct
50 Correct 138 ms 17084 KB Output is correct
51 Correct 385 ms 35688 KB Output is correct
52 Correct 356 ms 38296 KB Output is correct
53 Correct 92 ms 12552 KB Output is correct
54 Correct 11 ms 4272 KB Output is correct
55 Correct 20 ms 6960 KB Output is correct
56 Correct 35 ms 5544 KB Output is correct
57 Correct 305 ms 43628 KB Output is correct
58 Correct 36 ms 8584 KB Output is correct
59 Correct 88 ms 11272 KB Output is correct
60 Correct 110 ms 14696 KB Output is correct
61 Correct 98 ms 13448 KB Output is correct
62 Correct 548 ms 55420 KB Output is correct
63 Execution timed out 1056 ms 154512 KB Time limit exceeded
64 Halted 0 ms 0 KB -