답안 #163681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163681 2019-11-14T14:46:31 Z Minnakhmetov Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
475 ms 74900 KB
#include <bits/stdc++.h>
    
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
using namespace std;

struct E {
	int to, w;
};

const int N = 3e4 + 5, P = 70, V = N + N + N * P, INF = 1e9;
vector<E> g[N + N];
int d[V];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
    	int x, y;
    	cin >> x >> y;
    	g[m + x].push_back({i, 0});
    	g[i].push_back({m + x, 0});

    	if (y < P) {
    		g[i].push_back({n + m + x * P + y, 0});
    	}
    	else {
			int z = x - y, w = 1;
			while (z >= 0) {
				g[i].push_back({m + z, w});
				z -= y;
				w++;
			}
			z = x + y, w = 1;
			while (z < n) {
				g[i].push_back({m + z, w});
				z += y;
				w++;
			}
    	}
    }

    // for (int i = 0; i < n; i++) {
    // 	for (int j = 1; j < P; j++) {
    // 		int ver = n + m + i * P + j;
    // 		g[ver].push_back({m + i, 0});
    // 		if (i - j >= 0) {
    // 			g[ver].push_back({ver - j * P, 1});
    // 		}
    // 		if (i + j < n) {
    // 			g[ver].push_back({ver + j * P, 1});
    // 		}
    // 	}
    // }

    fill(d, d + V, INF);
    d[0] = 0;

    priority_queue<pair<int, int>, 
    			   vector<pair<int, int>>, 
    			   greater<pair<int, int>>> q;

    q.push({d[0], 0});

    while (!q.empty()) {
    	int node = q.top().second,
    		 cd = q.top().first;

    	q.pop();

    	if (cd != d[node])
    		continue;

    	if (node < n + m) {
			for (E e : g[node]) {
				if (d[e.to] > cd + e.w) {
					d[e.to] = cd + e.w;
					q.push({d[e.to], e.to});
				}
			}
    	}
    	else {
    		int x = (node - n - m) / P,
    			y = node - n - m - x * P;

    		if (d[m + x] > cd) {
    			d[m + x] = cd;
    			q.push({d[m + x], m + x});
    		}
    		if (x - y >= 0 && d[node - y * P] > cd + 1) {
    			d[node - y * P] = cd + 1;
    			q.push({d[node - y * P], node - y * P});
    		}
    		if (x + y < n && d[node + y * P] > cd + 1) {
    			d[node + y * P] = cd + 1;
    			q.push({d[node + y * P], node + y * P});
    		}
    	}
    }

    cout << (d[1] < INF ? d[1] : -1);

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10232 KB Output is correct
2 Correct 11 ms 10232 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10232 KB Output is correct
5 Correct 11 ms 10232 KB Output is correct
6 Correct 11 ms 10232 KB Output is correct
7 Correct 11 ms 10232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10232 KB Output is correct
2 Correct 11 ms 10236 KB Output is correct
3 Correct 10 ms 10232 KB Output is correct
4 Correct 11 ms 10164 KB Output is correct
5 Correct 11 ms 10232 KB Output is correct
6 Correct 11 ms 10232 KB Output is correct
7 Correct 11 ms 10232 KB Output is correct
8 Correct 11 ms 10236 KB Output is correct
9 Correct 11 ms 10232 KB Output is correct
10 Correct 11 ms 10232 KB Output is correct
11 Correct 12 ms 10360 KB Output is correct
12 Correct 12 ms 10360 KB Output is correct
13 Correct 12 ms 10360 KB Output is correct
14 Correct 13 ms 10360 KB Output is correct
15 Correct 13 ms 10360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 10232 KB Output is correct
2 Correct 11 ms 10232 KB Output is correct
3 Correct 11 ms 10204 KB Output is correct
4 Correct 11 ms 10232 KB Output is correct
5 Correct 11 ms 10232 KB Output is correct
6 Correct 11 ms 10232 KB Output is correct
7 Correct 11 ms 10232 KB Output is correct
8 Correct 11 ms 10232 KB Output is correct
9 Correct 12 ms 10232 KB Output is correct
10 Correct 12 ms 10232 KB Output is correct
11 Correct 13 ms 10364 KB Output is correct
12 Correct 12 ms 10360 KB Output is correct
13 Correct 12 ms 10360 KB Output is correct
14 Correct 13 ms 10360 KB Output is correct
15 Correct 13 ms 10360 KB Output is correct
16 Correct 11 ms 10232 KB Output is correct
17 Correct 13 ms 10360 KB Output is correct
18 Correct 11 ms 10360 KB Output is correct
19 Correct 11 ms 10232 KB Output is correct
20 Correct 12 ms 10364 KB Output is correct
21 Correct 12 ms 10232 KB Output is correct
22 Correct 11 ms 10232 KB Output is correct
23 Correct 12 ms 10268 KB Output is correct
24 Correct 14 ms 10360 KB Output is correct
25 Correct 12 ms 10360 KB Output is correct
26 Correct 12 ms 10360 KB Output is correct
27 Correct 12 ms 10360 KB Output is correct
28 Correct 14 ms 10360 KB Output is correct
29 Correct 18 ms 10232 KB Output is correct
30 Correct 12 ms 10236 KB Output is correct
31 Correct 15 ms 10236 KB Output is correct
32 Correct 14 ms 10232 KB Output is correct
33 Correct 26 ms 10360 KB Output is correct
34 Correct 26 ms 10360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 10232 KB Output is correct
2 Correct 10 ms 10232 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10232 KB Output is correct
5 Correct 10 ms 10232 KB Output is correct
6 Correct 11 ms 10232 KB Output is correct
7 Correct 11 ms 10204 KB Output is correct
8 Correct 11 ms 10232 KB Output is correct
9 Correct 12 ms 10232 KB Output is correct
10 Correct 11 ms 10204 KB Output is correct
11 Correct 12 ms 10360 KB Output is correct
12 Correct 12 ms 10232 KB Output is correct
13 Correct 12 ms 10360 KB Output is correct
14 Correct 13 ms 10360 KB Output is correct
15 Correct 13 ms 10360 KB Output is correct
16 Correct 11 ms 10232 KB Output is correct
17 Correct 13 ms 10360 KB Output is correct
18 Correct 11 ms 10360 KB Output is correct
19 Correct 11 ms 10232 KB Output is correct
20 Correct 12 ms 10360 KB Output is correct
21 Correct 2 ms 10232 KB Output is correct
22 Correct 11 ms 10232 KB Output is correct
23 Correct 12 ms 10232 KB Output is correct
24 Correct 13 ms 10360 KB Output is correct
25 Correct 12 ms 10360 KB Output is correct
26 Correct 13 ms 10360 KB Output is correct
27 Correct 12 ms 10360 KB Output is correct
28 Correct 13 ms 10360 KB Output is correct
29 Correct 18 ms 10232 KB Output is correct
30 Correct 13 ms 10232 KB Output is correct
31 Correct 15 ms 10232 KB Output is correct
32 Correct 14 ms 10232 KB Output is correct
33 Correct 26 ms 10360 KB Output is correct
34 Correct 26 ms 10360 KB Output is correct
35 Correct 34 ms 11896 KB Output is correct
36 Correct 14 ms 10488 KB Output is correct
37 Correct 37 ms 12024 KB Output is correct
38 Correct 41 ms 12152 KB Output is correct
39 Correct 41 ms 12152 KB Output is correct
40 Correct 42 ms 12152 KB Output is correct
41 Correct 41 ms 12176 KB Output is correct
42 Correct 24 ms 11892 KB Output is correct
43 Correct 24 ms 11892 KB Output is correct
44 Correct 25 ms 11764 KB Output is correct
45 Correct 58 ms 15092 KB Output is correct
46 Correct 59 ms 15096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 10232 KB Output is correct
2 Correct 11 ms 10236 KB Output is correct
3 Correct 11 ms 10232 KB Output is correct
4 Correct 11 ms 10232 KB Output is correct
5 Correct 11 ms 10232 KB Output is correct
6 Correct 11 ms 10232 KB Output is correct
7 Correct 11 ms 10232 KB Output is correct
8 Correct 11 ms 10232 KB Output is correct
9 Correct 11 ms 10232 KB Output is correct
10 Correct 11 ms 10232 KB Output is correct
11 Correct 13 ms 10360 KB Output is correct
12 Correct 12 ms 10360 KB Output is correct
13 Correct 12 ms 10360 KB Output is correct
14 Correct 13 ms 10332 KB Output is correct
15 Correct 12 ms 10360 KB Output is correct
16 Correct 11 ms 10232 KB Output is correct
17 Correct 14 ms 10360 KB Output is correct
18 Correct 11 ms 10232 KB Output is correct
19 Correct 11 ms 10232 KB Output is correct
20 Correct 12 ms 10360 KB Output is correct
21 Correct 11 ms 10236 KB Output is correct
22 Correct 11 ms 10232 KB Output is correct
23 Correct 12 ms 10232 KB Output is correct
24 Correct 14 ms 10360 KB Output is correct
25 Correct 13 ms 10360 KB Output is correct
26 Correct 13 ms 10360 KB Output is correct
27 Correct 12 ms 10360 KB Output is correct
28 Correct 14 ms 10360 KB Output is correct
29 Correct 18 ms 10232 KB Output is correct
30 Correct 13 ms 10232 KB Output is correct
31 Correct 24 ms 10232 KB Output is correct
32 Correct 14 ms 10232 KB Output is correct
33 Correct 26 ms 10360 KB Output is correct
34 Correct 26 ms 10360 KB Output is correct
35 Correct 34 ms 11768 KB Output is correct
36 Correct 16 ms 10488 KB Output is correct
37 Correct 38 ms 12024 KB Output is correct
38 Correct 42 ms 12156 KB Output is correct
39 Correct 43 ms 12124 KB Output is correct
40 Correct 42 ms 12152 KB Output is correct
41 Correct 42 ms 12152 KB Output is correct
42 Correct 25 ms 12020 KB Output is correct
43 Correct 24 ms 11856 KB Output is correct
44 Correct 25 ms 11764 KB Output is correct
45 Correct 56 ms 15096 KB Output is correct
46 Correct 67 ms 15096 KB Output is correct
47 Correct 104 ms 16376 KB Output is correct
48 Correct 27 ms 12408 KB Output is correct
49 Correct 26 ms 12280 KB Output is correct
50 Correct 22 ms 11768 KB Output is correct
51 Correct 81 ms 13688 KB Output is correct
52 Correct 184 ms 13816 KB Output is correct
53 Correct 39 ms 11768 KB Output is correct
54 Correct 12 ms 10232 KB Output is correct
55 Correct 13 ms 10232 KB Output is correct
56 Correct 32 ms 12024 KB Output is correct
57 Correct 93 ms 10408 KB Output is correct
58 Correct 28 ms 11892 KB Output is correct
59 Correct 36 ms 11892 KB Output is correct
60 Correct 38 ms 12404 KB Output is correct
61 Correct 33 ms 12148 KB Output is correct
62 Correct 63 ms 14712 KB Output is correct
63 Correct 121 ms 37332 KB Output is correct
64 Correct 136 ms 45036 KB Output is correct
65 Correct 204 ms 56616 KB Output is correct
66 Correct 475 ms 74860 KB Output is correct
67 Correct 471 ms 74900 KB Output is correct