답안 #25162

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25162 2017-06-20T10:58:59 Z kajebiii Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
159 ms 9252 KB
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 3e4 + 100;
int N, M, St, En;
vector<int> List[MAX_N];
int main() {
	cin >> N >> M;
	REP(i, M) {
		int x, p; scanf("%d%d", &x, &p);
		if(i == 0) St = x;
		if(i == 1) En = x;
		List[x].push_back(p);
	}
	for(int i=0; i<N; i++) {
		sort(ALL(List[i]));
		List[i].erase(unique(ALL(List[i])), List[i].end());
	}

	priority_queue<pi, vector<pi>, greater<pi> > Q;
	vector<int> dis(N+1, INF);
	Q.push(pi(0, St)); dis[St] = 0;
	while(!Q.empty()) {
		int d, x; tie(d, x) = Q.top(); Q.pop();
		if(dis[x] < d) continue;
		for(int p : List[x]) {
			for(int i=x+p, cnt=1; i<N; i+=p, cnt++) {
				if(dis[i] > d+cnt)
					Q.push(pi(dis[i] = d+cnt, i));
				int ix = lower_bound(ALL(List[i]), p) - List[i].begin();
				if(ix < SZ(List[i]) && List[i][ix] == p) break;
			}
			for(int i=x-p, cnt=1; i>=0; i-=p, cnt++) {
				if(dis[i] > d+cnt)
					Q.push(pi(dis[i] = d+cnt, i));
				int ix = lower_bound(ALL(List[i]), p) - List[i].begin();
				if(ix < SZ(List[i]) && List[i][ix] == p) break;
			}
		}
	}
	if(dis[En] == INF) dis[En] = -1;
	printf("%d\n", dis[En]);
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, p; scanf("%d%d", &x, &p);
                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2728 KB Output is correct
2 Correct 0 ms 2728 KB Output is correct
3 Correct 0 ms 2728 KB Output is correct
4 Correct 0 ms 2728 KB Output is correct
5 Correct 0 ms 2728 KB Output is correct
6 Correct 0 ms 2728 KB Output is correct
7 Correct 0 ms 2728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2728 KB Output is correct
2 Correct 0 ms 2728 KB Output is correct
3 Correct 0 ms 2728 KB Output is correct
4 Correct 0 ms 2728 KB Output is correct
5 Correct 0 ms 2728 KB Output is correct
6 Correct 0 ms 2728 KB Output is correct
7 Correct 0 ms 2728 KB Output is correct
8 Correct 0 ms 2728 KB Output is correct
9 Correct 0 ms 2728 KB Output is correct
10 Correct 0 ms 2728 KB Output is correct
11 Correct 0 ms 2728 KB Output is correct
12 Correct 0 ms 2728 KB Output is correct
13 Correct 0 ms 2728 KB Output is correct
14 Correct 0 ms 2728 KB Output is correct
15 Correct 0 ms 2728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2728 KB Output is correct
2 Correct 0 ms 2728 KB Output is correct
3 Correct 0 ms 2728 KB Output is correct
4 Correct 0 ms 2728 KB Output is correct
5 Correct 0 ms 2728 KB Output is correct
6 Correct 0 ms 2728 KB Output is correct
7 Correct 0 ms 2728 KB Output is correct
8 Correct 0 ms 2728 KB Output is correct
9 Correct 0 ms 2728 KB Output is correct
10 Correct 0 ms 2728 KB Output is correct
11 Correct 0 ms 2728 KB Output is correct
12 Correct 0 ms 2728 KB Output is correct
13 Correct 0 ms 2728 KB Output is correct
14 Correct 0 ms 2728 KB Output is correct
15 Correct 0 ms 2728 KB Output is correct
16 Correct 0 ms 2728 KB Output is correct
17 Correct 0 ms 2860 KB Output is correct
18 Correct 0 ms 2728 KB Output is correct
19 Correct 0 ms 2728 KB Output is correct
20 Correct 0 ms 2860 KB Output is correct
21 Correct 0 ms 2728 KB Output is correct
22 Correct 0 ms 2728 KB Output is correct
23 Correct 0 ms 2728 KB Output is correct
24 Correct 3 ms 2864 KB Output is correct
25 Correct 3 ms 2860 KB Output is correct
26 Correct 0 ms 2728 KB Output is correct
27 Correct 0 ms 2728 KB Output is correct
28 Correct 0 ms 2860 KB Output is correct
29 Correct 3 ms 3012 KB Output is correct
30 Correct 0 ms 2876 KB Output is correct
31 Correct 0 ms 2880 KB Output is correct
32 Correct 0 ms 2880 KB Output is correct
33 Correct 3 ms 3220 KB Output is correct
34 Correct 6 ms 3220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2728 KB Output is correct
2 Correct 0 ms 2728 KB Output is correct
3 Correct 0 ms 2728 KB Output is correct
4 Correct 0 ms 2728 KB Output is correct
5 Correct 0 ms 2728 KB Output is correct
6 Correct 0 ms 2728 KB Output is correct
7 Correct 0 ms 2728 KB Output is correct
8 Correct 0 ms 2728 KB Output is correct
9 Correct 0 ms 2728 KB Output is correct
10 Correct 0 ms 2728 KB Output is correct
11 Correct 0 ms 2728 KB Output is correct
12 Correct 0 ms 2728 KB Output is correct
13 Correct 0 ms 2728 KB Output is correct
14 Correct 0 ms 2728 KB Output is correct
15 Correct 0 ms 2728 KB Output is correct
16 Correct 0 ms 2728 KB Output is correct
17 Correct 0 ms 2860 KB Output is correct
18 Correct 0 ms 2728 KB Output is correct
19 Correct 0 ms 2728 KB Output is correct
20 Correct 0 ms 2860 KB Output is correct
21 Correct 0 ms 2728 KB Output is correct
22 Correct 0 ms 2728 KB Output is correct
23 Correct 0 ms 2728 KB Output is correct
24 Correct 3 ms 2864 KB Output is correct
25 Correct 3 ms 2860 KB Output is correct
26 Correct 0 ms 2728 KB Output is correct
27 Correct 0 ms 2728 KB Output is correct
28 Correct 0 ms 2860 KB Output is correct
29 Correct 3 ms 3012 KB Output is correct
30 Correct 0 ms 2876 KB Output is correct
31 Correct 0 ms 2880 KB Output is correct
32 Correct 0 ms 2880 KB Output is correct
33 Correct 3 ms 3220 KB Output is correct
34 Correct 3 ms 3220 KB Output is correct
35 Correct 9 ms 2992 KB Output is correct
36 Correct 0 ms 2860 KB Output is correct
37 Correct 13 ms 2996 KB Output is correct
38 Correct 16 ms 3184 KB Output is correct
39 Correct 19 ms 3180 KB Output is correct
40 Correct 13 ms 3184 KB Output is correct
41 Correct 13 ms 3184 KB Output is correct
42 Correct 3 ms 3004 KB Output is correct
43 Correct 3 ms 3004 KB Output is correct
44 Correct 9 ms 3000 KB Output is correct
45 Correct 13 ms 3380 KB Output is correct
46 Correct 13 ms 3384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2728 KB Output is correct
2 Correct 0 ms 2728 KB Output is correct
3 Correct 0 ms 2728 KB Output is correct
4 Correct 0 ms 2728 KB Output is correct
5 Correct 0 ms 2728 KB Output is correct
6 Correct 0 ms 2728 KB Output is correct
7 Correct 0 ms 2728 KB Output is correct
8 Correct 0 ms 2728 KB Output is correct
9 Correct 0 ms 2728 KB Output is correct
10 Correct 0 ms 2728 KB Output is correct
11 Correct 0 ms 2728 KB Output is correct
12 Correct 0 ms 2728 KB Output is correct
13 Correct 0 ms 2728 KB Output is correct
14 Correct 0 ms 2728 KB Output is correct
15 Correct 0 ms 2728 KB Output is correct
16 Correct 0 ms 2728 KB Output is correct
17 Correct 0 ms 2860 KB Output is correct
18 Correct 0 ms 2728 KB Output is correct
19 Correct 0 ms 2728 KB Output is correct
20 Correct 0 ms 2860 KB Output is correct
21 Correct 0 ms 2728 KB Output is correct
22 Correct 0 ms 2728 KB Output is correct
23 Correct 0 ms 2728 KB Output is correct
24 Correct 0 ms 2864 KB Output is correct
25 Correct 0 ms 2860 KB Output is correct
26 Correct 0 ms 2728 KB Output is correct
27 Correct 0 ms 2728 KB Output is correct
28 Correct 0 ms 2860 KB Output is correct
29 Correct 3 ms 3012 KB Output is correct
30 Correct 0 ms 2876 KB Output is correct
31 Correct 0 ms 2880 KB Output is correct
32 Correct 0 ms 2880 KB Output is correct
33 Correct 3 ms 3220 KB Output is correct
34 Correct 3 ms 3220 KB Output is correct
35 Correct 6 ms 2992 KB Output is correct
36 Correct 3 ms 2860 KB Output is correct
37 Correct 9 ms 2996 KB Output is correct
38 Correct 13 ms 3184 KB Output is correct
39 Correct 16 ms 3180 KB Output is correct
40 Correct 13 ms 3184 KB Output is correct
41 Correct 13 ms 3184 KB Output is correct
42 Correct 6 ms 3004 KB Output is correct
43 Correct 9 ms 3004 KB Output is correct
44 Correct 6 ms 3000 KB Output is correct
45 Correct 16 ms 3380 KB Output is correct
46 Correct 13 ms 3384 KB Output is correct
47 Correct 33 ms 3972 KB Output is correct
48 Correct 9 ms 3344 KB Output is correct
49 Correct 9 ms 3352 KB Output is correct
50 Correct 6 ms 3272 KB Output is correct
51 Correct 33 ms 4288 KB Output is correct
52 Correct 33 ms 4292 KB Output is correct
53 Correct 16 ms 4292 KB Output is correct
54 Correct 0 ms 3052 KB Output is correct
55 Correct 0 ms 3052 KB Output is correct
56 Correct 9 ms 3860 KB Output is correct
57 Correct 29 ms 3768 KB Output is correct
58 Correct 3 ms 3200 KB Output is correct
59 Correct 9 ms 3204 KB Output is correct
60 Correct 9 ms 3208 KB Output is correct
61 Correct 9 ms 3220 KB Output is correct
62 Correct 13 ms 3860 KB Output is correct
63 Correct 49 ms 6236 KB Output is correct
64 Correct 63 ms 6200 KB Output is correct
65 Correct 73 ms 6220 KB Output is correct
66 Correct 159 ms 9252 KB Output is correct
67 Correct 159 ms 9248 KB Output is correct