답안 #15879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
15879 2015-07-31T18:58:10 Z myungwoo Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
101 ms 11656 KB
#include <bits/stdc++.h>
using namespace std;

#define MAXN 30005
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;

int N, M, S, E;
int D[MAXN];
bool V[MAXN][200];
vector <int> doge[MAXN];

int main()
{
	scanf("%d%d", &N, &M);
	for (int i=0;i<M;i++){
		int b, p;
		scanf("%d%d", &b, &p);
		if (p > 199 || !V[b][p]) doge[b].pb(p);
		if (p < 200) V[b][p] = 1;
		if (!i) S = b;
		if (i == 1) E = b;
	}
	for (int i=0;i<N;i++) D[i] = 2e9;
	priority_queue <pii> que;
	D[S] = 0;
	que.push(mp(0, S));
	while (!que.empty()){
		int q = que.top().second, d = -que.top().first; que.pop();
		if (D[q] != d) continue;
		for (int p: doge[q]){
			for (int i=q-p;i>=0;i-=p){
				if (D[i] > d+(q-i)/p)
					D[i] = d+(q-i)/p, que.push(mp(-D[i], i));
				if (p < 200 && V[i][p]) break;
			}
			for (int i=q+p;i<N;i+=p){
				if (D[i] > d+(i-q)/p)
					D[i] = d+(i-q)/p, que.push(mp(-D[i], i));
				if (p < 200 && V[i][p]) break;
			}
		}
	}
	printf("%d\n", D[E] < 2e9 ? D[E] : -1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8400 KB Output is correct
2 Correct 0 ms 8400 KB Output is correct
3 Correct 0 ms 8400 KB Output is correct
4 Correct 0 ms 8400 KB Output is correct
5 Correct 0 ms 8400 KB Output is correct
6 Correct 0 ms 8400 KB Output is correct
7 Correct 0 ms 8400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8400 KB Output is correct
2 Correct 0 ms 8400 KB Output is correct
3 Correct 0 ms 8400 KB Output is correct
4 Correct 0 ms 8400 KB Output is correct
5 Correct 0 ms 8400 KB Output is correct
6 Correct 0 ms 8400 KB Output is correct
7 Correct 1 ms 8400 KB Output is correct
8 Correct 0 ms 8400 KB Output is correct
9 Correct 0 ms 8400 KB Output is correct
10 Correct 0 ms 8400 KB Output is correct
11 Correct 0 ms 8400 KB Output is correct
12 Correct 1 ms 8400 KB Output is correct
13 Correct 0 ms 8400 KB Output is correct
14 Correct 0 ms 8400 KB Output is correct
15 Correct 1 ms 8400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8400 KB Output is correct
2 Correct 0 ms 8400 KB Output is correct
3 Correct 0 ms 8400 KB Output is correct
4 Correct 0 ms 8400 KB Output is correct
5 Correct 0 ms 8400 KB Output is correct
6 Correct 0 ms 8400 KB Output is correct
7 Correct 0 ms 8400 KB Output is correct
8 Correct 0 ms 8400 KB Output is correct
9 Correct 0 ms 8400 KB Output is correct
10 Correct 0 ms 8400 KB Output is correct
11 Correct 0 ms 8400 KB Output is correct
12 Correct 1 ms 8400 KB Output is correct
13 Correct 0 ms 8400 KB Output is correct
14 Correct 0 ms 8400 KB Output is correct
15 Correct 0 ms 8400 KB Output is correct
16 Correct 0 ms 8400 KB Output is correct
17 Correct 0 ms 8400 KB Output is correct
18 Correct 0 ms 8400 KB Output is correct
19 Correct 0 ms 8400 KB Output is correct
20 Correct 0 ms 8400 KB Output is correct
21 Correct 0 ms 8400 KB Output is correct
22 Correct 0 ms 8400 KB Output is correct
23 Correct 0 ms 8400 KB Output is correct
24 Correct 0 ms 8400 KB Output is correct
25 Correct 0 ms 8400 KB Output is correct
26 Correct 0 ms 8400 KB Output is correct
27 Correct 0 ms 8400 KB Output is correct
28 Correct 0 ms 8400 KB Output is correct
29 Correct 2 ms 8536 KB Output is correct
30 Correct 2 ms 8400 KB Output is correct
31 Correct 0 ms 8536 KB Output is correct
32 Correct 0 ms 8536 KB Output is correct
33 Correct 4 ms 8544 KB Output is correct
34 Correct 0 ms 8544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8400 KB Output is correct
2 Correct 0 ms 8400 KB Output is correct
3 Correct 0 ms 8400 KB Output is correct
4 Correct 0 ms 8400 KB Output is correct
5 Correct 0 ms 8400 KB Output is correct
6 Correct 0 ms 8400 KB Output is correct
7 Correct 0 ms 8400 KB Output is correct
8 Correct 0 ms 8400 KB Output is correct
9 Correct 0 ms 8400 KB Output is correct
10 Correct 0 ms 8400 KB Output is correct
11 Correct 0 ms 8400 KB Output is correct
12 Correct 0 ms 8400 KB Output is correct
13 Correct 0 ms 8400 KB Output is correct
14 Correct 1 ms 8400 KB Output is correct
15 Correct 0 ms 8400 KB Output is correct
16 Correct 0 ms 8400 KB Output is correct
17 Correct 0 ms 8400 KB Output is correct
18 Correct 0 ms 8400 KB Output is correct
19 Correct 0 ms 8400 KB Output is correct
20 Correct 2 ms 8400 KB Output is correct
21 Correct 0 ms 8400 KB Output is correct
22 Correct 0 ms 8400 KB Output is correct
23 Correct 0 ms 8400 KB Output is correct
24 Correct 3 ms 8400 KB Output is correct
25 Correct 0 ms 8400 KB Output is correct
26 Correct 0 ms 8400 KB Output is correct
27 Correct 0 ms 8400 KB Output is correct
28 Correct 0 ms 8400 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 0 ms 8400 KB Output is correct
31 Correct 0 ms 8536 KB Output is correct
32 Correct 1 ms 8536 KB Output is correct
33 Correct 2 ms 8544 KB Output is correct
34 Correct 4 ms 8544 KB Output is correct
35 Correct 10 ms 8664 KB Output is correct
36 Correct 3 ms 8400 KB Output is correct
37 Correct 10 ms 8700 KB Output is correct
38 Correct 15 ms 8664 KB Output is correct
39 Correct 14 ms 8664 KB Output is correct
40 Correct 12 ms 8664 KB Output is correct
41 Correct 15 ms 8664 KB Output is correct
42 Correct 0 ms 8400 KB Output is correct
43 Correct 4 ms 8400 KB Output is correct
44 Correct 5 ms 8400 KB Output is correct
45 Correct 15 ms 8708 KB Output is correct
46 Correct 13 ms 8704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8400 KB Output is correct
2 Correct 0 ms 8400 KB Output is correct
3 Correct 0 ms 8400 KB Output is correct
4 Correct 0 ms 8400 KB Output is correct
5 Correct 0 ms 8400 KB Output is correct
6 Correct 0 ms 8400 KB Output is correct
7 Correct 0 ms 8400 KB Output is correct
8 Correct 0 ms 8400 KB Output is correct
9 Correct 0 ms 8400 KB Output is correct
10 Correct 0 ms 8400 KB Output is correct
11 Correct 0 ms 8400 KB Output is correct
12 Correct 0 ms 8400 KB Output is correct
13 Correct 0 ms 8400 KB Output is correct
14 Correct 0 ms 8400 KB Output is correct
15 Correct 0 ms 8400 KB Output is correct
16 Correct 0 ms 8400 KB Output is correct
17 Correct 0 ms 8400 KB Output is correct
18 Correct 1 ms 8400 KB Output is correct
19 Correct 0 ms 8400 KB Output is correct
20 Correct 2 ms 8400 KB Output is correct
21 Correct 0 ms 8400 KB Output is correct
22 Correct 0 ms 8400 KB Output is correct
23 Correct 0 ms 8400 KB Output is correct
24 Correct 0 ms 8400 KB Output is correct
25 Correct 0 ms 8400 KB Output is correct
26 Correct 0 ms 8400 KB Output is correct
27 Correct 0 ms 8400 KB Output is correct
28 Correct 2 ms 8400 KB Output is correct
29 Correct 3 ms 8536 KB Output is correct
30 Correct 0 ms 8400 KB Output is correct
31 Correct 2 ms 8536 KB Output is correct
32 Correct 0 ms 8536 KB Output is correct
33 Correct 3 ms 8544 KB Output is correct
34 Correct 3 ms 8544 KB Output is correct
35 Correct 12 ms 8664 KB Output is correct
36 Correct 2 ms 8400 KB Output is correct
37 Correct 11 ms 8700 KB Output is correct
38 Correct 14 ms 8664 KB Output is correct
39 Correct 15 ms 8664 KB Output is correct
40 Correct 8 ms 8664 KB Output is correct
41 Correct 7 ms 8664 KB Output is correct
42 Correct 6 ms 8400 KB Output is correct
43 Correct 7 ms 8400 KB Output is correct
44 Correct 8 ms 8400 KB Output is correct
45 Correct 7 ms 8708 KB Output is correct
46 Correct 14 ms 8704 KB Output is correct
47 Correct 29 ms 9516 KB Output is correct
48 Correct 12 ms 8796 KB Output is correct
49 Correct 0 ms 8796 KB Output is correct
50 Correct 0 ms 8664 KB Output is correct
51 Correct 32 ms 9764 KB Output is correct
52 Correct 37 ms 9768 KB Output is correct
53 Correct 19 ms 9768 KB Output is correct
54 Correct 4 ms 8532 KB Output is correct
55 Correct 3 ms 8532 KB Output is correct
56 Correct 13 ms 9324 KB Output is correct
57 Correct 36 ms 9244 KB Output is correct
58 Correct 11 ms 8532 KB Output is correct
59 Correct 14 ms 8532 KB Output is correct
60 Correct 7 ms 8536 KB Output is correct
61 Correct 9 ms 8556 KB Output is correct
62 Correct 19 ms 9324 KB Output is correct
63 Correct 40 ms 10180 KB Output is correct
64 Correct 45 ms 10140 KB Output is correct
65 Correct 57 ms 10152 KB Output is correct
66 Correct 101 ms 11652 KB Output is correct
67 Correct 96 ms 11656 KB Output is correct