답안 #441712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441712 2021-07-05T21:25:38 Z dutch Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
87 ms 4928 KB
#pragma GCC optimize("Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define DIJKSTRA if(d[v] > dist + w) q.push({-(d[v] = dist + w), v})
 
const int SQRT = 2, MAXN = 3e4, INF = 2e9;
vector<array<int, 2>> g[MAXN*SQRT];
vector<int> h[MAXN];
int n, m, b, p, s, t, d[MAXN*SQRT];
 
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
 
	for(int _=0; _<m; ++_){
		cin >> b >> p;
		if(_ == 0) s = b;
		if(_ == 1) t = b;
		int c = b * SQRT;
		if(p < SQRT) g[c].push_back({c+p, 0});
		else h[b].push_back(p);
	}
 
	priority_queue<array<int, 2>> q;
	fill(d, d+n*SQRT, INF);
	q.push({d[s*SQRT] = 0, s*SQRT});
 
	while(!q.empty()){
		int u = q.top()[1], dist = -q.top()[0];
		q.pop();
		if(dist != d[u]) continue;
		for(auto &[v, w] : g[u]) DIJKSTRA;
 
		int j = u % SQRT, v = u - j, w = 0;
		DIJKSTRA;
 
		for(int x : {-1, 1}){
			v = u+ x * j * SQRT, w = 1;
			if(0<=v && v<n*SQRT) DIJKSTRA;
		}
 
		if(j) continue;
		b = u / SQRT;
		for(int &k : h[b]) for(int i=b%k; i<n; i+=k){
			v = i*SQRT, w = abs(b-i)/k;
			DIJKSTRA;
		}
	}
 
	if(d[t*SQRT] == INF) d[t*SQRT] = -1;
	cout << d[t*SQRT];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2380 KB Output is correct
2 Correct 2 ms 2380 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2380 KB Output is correct
5 Correct 2 ms 2380 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
7 Correct 2 ms 2380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2380 KB Output is correct
2 Correct 2 ms 2380 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2380 KB Output is correct
5 Correct 2 ms 2380 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
7 Correct 2 ms 2380 KB Output is correct
8 Correct 2 ms 2372 KB Output is correct
9 Correct 2 ms 2380 KB Output is correct
10 Correct 2 ms 2380 KB Output is correct
11 Correct 2 ms 2380 KB Output is correct
12 Correct 2 ms 2380 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 2 ms 2380 KB Output is correct
15 Correct 2 ms 2380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2380 KB Output is correct
2 Correct 2 ms 2380 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2380 KB Output is correct
5 Correct 2 ms 2380 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
7 Correct 2 ms 2380 KB Output is correct
8 Correct 2 ms 2380 KB Output is correct
9 Correct 2 ms 2380 KB Output is correct
10 Correct 2 ms 2380 KB Output is correct
11 Correct 2 ms 2380 KB Output is correct
12 Correct 2 ms 2380 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 2 ms 2380 KB Output is correct
15 Correct 2 ms 2380 KB Output is correct
16 Correct 2 ms 2380 KB Output is correct
17 Correct 3 ms 2380 KB Output is correct
18 Correct 2 ms 2380 KB Output is correct
19 Correct 2 ms 2380 KB Output is correct
20 Correct 2 ms 2508 KB Output is correct
21 Correct 2 ms 2380 KB Output is correct
22 Correct 2 ms 2380 KB Output is correct
23 Correct 2 ms 2380 KB Output is correct
24 Correct 3 ms 2508 KB Output is correct
25 Correct 3 ms 2508 KB Output is correct
26 Correct 2 ms 2380 KB Output is correct
27 Correct 2 ms 2380 KB Output is correct
28 Correct 3 ms 2508 KB Output is correct
29 Correct 3 ms 2508 KB Output is correct
30 Correct 2 ms 2380 KB Output is correct
31 Correct 3 ms 2508 KB Output is correct
32 Correct 2 ms 2508 KB Output is correct
33 Correct 4 ms 2636 KB Output is correct
34 Correct 4 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2380 KB Output is correct
2 Correct 2 ms 2380 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2380 KB Output is correct
5 Correct 2 ms 2380 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
7 Correct 2 ms 2380 KB Output is correct
8 Correct 2 ms 2380 KB Output is correct
9 Correct 2 ms 2380 KB Output is correct
10 Correct 2 ms 2380 KB Output is correct
11 Correct 2 ms 2380 KB Output is correct
12 Correct 2 ms 2380 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 2 ms 2380 KB Output is correct
15 Correct 2 ms 2380 KB Output is correct
16 Correct 2 ms 2380 KB Output is correct
17 Correct 3 ms 2380 KB Output is correct
18 Correct 4 ms 2380 KB Output is correct
19 Correct 2 ms 2380 KB Output is correct
20 Correct 2 ms 2508 KB Output is correct
21 Correct 2 ms 2380 KB Output is correct
22 Correct 2 ms 2380 KB Output is correct
23 Correct 2 ms 2380 KB Output is correct
24 Correct 3 ms 2508 KB Output is correct
25 Correct 3 ms 2508 KB Output is correct
26 Correct 3 ms 2380 KB Output is correct
27 Correct 2 ms 2380 KB Output is correct
28 Correct 3 ms 2508 KB Output is correct
29 Correct 4 ms 2636 KB Output is correct
30 Correct 2 ms 2508 KB Output is correct
31 Correct 3 ms 2508 KB Output is correct
32 Correct 2 ms 2508 KB Output is correct
33 Correct 5 ms 2580 KB Output is correct
34 Correct 4 ms 2480 KB Output is correct
35 Correct 12 ms 2664 KB Output is correct
36 Correct 3 ms 2508 KB Output is correct
37 Correct 9 ms 2636 KB Output is correct
38 Correct 11 ms 2764 KB Output is correct
39 Correct 11 ms 2788 KB Output is correct
40 Correct 12 ms 2764 KB Output is correct
41 Correct 11 ms 2792 KB Output is correct
42 Correct 7 ms 2784 KB Output is correct
43 Correct 7 ms 2764 KB Output is correct
44 Correct 7 ms 2804 KB Output is correct
45 Correct 11 ms 2764 KB Output is correct
46 Correct 11 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2380 KB Output is correct
2 Correct 2 ms 2380 KB Output is correct
3 Correct 2 ms 2380 KB Output is correct
4 Correct 2 ms 2380 KB Output is correct
5 Correct 2 ms 2380 KB Output is correct
6 Correct 2 ms 2380 KB Output is correct
7 Correct 2 ms 2380 KB Output is correct
8 Correct 2 ms 2380 KB Output is correct
9 Correct 2 ms 2380 KB Output is correct
10 Correct 2 ms 2380 KB Output is correct
11 Correct 2 ms 2380 KB Output is correct
12 Correct 2 ms 2380 KB Output is correct
13 Correct 2 ms 2380 KB Output is correct
14 Correct 2 ms 2380 KB Output is correct
15 Correct 2 ms 2380 KB Output is correct
16 Correct 2 ms 2380 KB Output is correct
17 Correct 3 ms 2380 KB Output is correct
18 Correct 2 ms 2380 KB Output is correct
19 Correct 2 ms 2380 KB Output is correct
20 Correct 2 ms 2508 KB Output is correct
21 Correct 2 ms 2380 KB Output is correct
22 Correct 3 ms 2380 KB Output is correct
23 Correct 3 ms 2496 KB Output is correct
24 Correct 3 ms 2524 KB Output is correct
25 Correct 3 ms 2508 KB Output is correct
26 Correct 3 ms 2380 KB Output is correct
27 Correct 2 ms 2380 KB Output is correct
28 Correct 2 ms 2508 KB Output is correct
29 Correct 3 ms 2508 KB Output is correct
30 Correct 2 ms 2380 KB Output is correct
31 Correct 3 ms 2508 KB Output is correct
32 Correct 2 ms 2508 KB Output is correct
33 Correct 4 ms 2560 KB Output is correct
34 Correct 4 ms 2508 KB Output is correct
35 Correct 10 ms 2636 KB Output is correct
36 Correct 3 ms 2508 KB Output is correct
37 Correct 9 ms 2696 KB Output is correct
38 Correct 11 ms 2764 KB Output is correct
39 Correct 12 ms 2756 KB Output is correct
40 Correct 13 ms 2784 KB Output is correct
41 Correct 12 ms 2764 KB Output is correct
42 Correct 7 ms 2764 KB Output is correct
43 Correct 7 ms 2764 KB Output is correct
44 Correct 7 ms 2836 KB Output is correct
45 Correct 11 ms 2764 KB Output is correct
46 Correct 12 ms 2772 KB Output is correct
47 Correct 24 ms 3480 KB Output is correct
48 Correct 8 ms 2988 KB Output is correct
49 Correct 8 ms 3020 KB Output is correct
50 Correct 6 ms 2892 KB Output is correct
51 Correct 27 ms 3860 KB Output is correct
52 Correct 35 ms 3912 KB Output is correct
53 Correct 18 ms 3532 KB Output is correct
54 Correct 3 ms 2892 KB Output is correct
55 Correct 4 ms 2892 KB Output is correct
56 Correct 11 ms 3560 KB Output is correct
57 Correct 87 ms 4928 KB Output is correct
58 Correct 9 ms 3152 KB Output is correct
59 Correct 12 ms 3152 KB Output is correct
60 Correct 12 ms 3148 KB Output is correct
61 Correct 12 ms 3156 KB Output is correct
62 Correct 16 ms 3488 KB Output is correct
63 Correct 34 ms 3536 KB Output is correct
64 Correct 38 ms 3528 KB Output is correct
65 Correct 47 ms 4044 KB Output is correct
66 Correct 76 ms 4036 KB Output is correct
67 Correct 81 ms 4036 KB Output is correct