답안 #248518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
248518 2020-07-12T15:10:51 Z sahil_k Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
195 ms 65764 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
using namespace std;
/*
int n, m;
set<int> inc[30100];
vector< pair<int, int> > adj[2000000];
int dist[2000000];
bool vis[2000000];
priority_queue< pair<int, int> > ord;
int main () {
	cin >> n >> m;
	int rt = sqrt(n);
	int start, end;
	for (int i=0; i<n; i++) {
		for (int j=1; j<rt; j++) {
			adj[i*rt+j].push_back({i*rt, 0});
			if (i-j >= 0) adj[i*rt+j].push_back({(i-j)*rt+j, 1});
			if (i+j < n) adj[i*rt+j].push_back({(i+j)*rt+j, 1});
		}
	}
	int bi, pi;
	for (int i=0; i<m; i++) {
		cin >> bi >> pi;
		if (i == 0) start = bi;
		if (i == 1) end = bi;
		if (pi < rt) {
			adj[bi*rt].push_back({bi*rt+pi, 0});
		} else {
			for (int j=1; j<n; j++) {
				if (bi-j*pi < 0 && bi+j*pi >= n) break;
				if (bi-j*pi >= 0) adj[bi*rt].push_back({(bi-j*pi)*rt, j});
				if (bi+j*pi < n) adj[bi*rt].push_back({(bi+j*pi)*rt, j});
			}
		}
	}
	for (int i=0; i<n*rt; i++) {
		dist[i] = 1e9;
		vis[i] = false;
	}
	dist[start*rt] = 0;
	ord.push({0, start*rt});
	while (ord.size() > 0) {
		pair<int, int> cur = ord.top();
		cur.first = -cur.first;
		ord.pop();
		if (cur.second == end*rt) {
			cout << cur.first << endl;
			return 0;
		}
		if (vis[cur.second]) continue;
		vis[cur.second] = true;
		for (auto i: adj[cur.second]) {
			if (!vis[i.first] && cur.first+i.second < dist[i.first]) {
				dist[i.first] = cur.first+i.second;
				ord.push({-dist[i.first], i.first});
			}
		}
	}
	cout << -1 << endl;
}
*/

int n, m;
set<int> inc[30100];
vector< pair<int, int> > adj[30100];
int dist[30100];
bool vis[30100];
priority_queue< pair<int, int> > pq;
int main () {
	cin >> n >> m;
	int bi, pi;
	int start, end;
	for (int i=0; i<m; i++) {
		cin >> bi >> pi;
		inc[bi].insert(pi);
		if (i == 0) start = bi;
		if (i == 1) end = bi;
	}
	for (int i=0; i<n; i++) {
		for (auto j: inc[i]) {
			for (int k=1; k<n; k++) {
				if (i-j*k < 0) break;
				if (inc[i-j*k].find(j) != inc[i-j*k].end()) {
					adj[i].push_back({i-j*k, k});
					break;
				}
				adj[i].push_back({i-j*k, k});
			}
			for (int k=1; k<n; k++) {
				if (i+j*k >= n) break;
				if (inc[i+j*k].find(j) != inc[i+j*k].end()) {
					adj[i].push_back({i+j*k, k});
					break;
				}
				adj[i].push_back({i+j*k, k});
			}
		}
	}
	for (int i=0; i<n; i++) {
		dist[i] = 1e9;
	} 
	dist[start] = 0;
	pq.push({0, start});
	while (pq.size() > 0) {
		pair<int, int> cur = pq.top();
		cur.first = -cur.first;
		pq.pop();
		if (cur.second == end) {
			cout << cur.first << endl;
			return 0;
		}
		if (vis[cur.second]) continue;
		vis[cur.second] = true;
		for (auto i: adj[cur.second]) {
			if (!vis[i.first] && cur.first+i.second < dist[i.first]) {
				dist[i.first] = cur.first+i.second;
				pq.push({-dist[i.first], i.first});
			}
		}
	}
	cout << -1 << endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:113:3: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (cur.second == end) {
   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 1 ms 2432 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Correct 1 ms 2432 KB Output is correct
6 Correct 1 ms 2432 KB Output is correct
7 Correct 2 ms 2432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 2 ms 2432 KB Output is correct
4 Correct 2 ms 2488 KB Output is correct
5 Correct 2 ms 2432 KB Output is correct
6 Correct 1 ms 2432 KB Output is correct
7 Correct 2 ms 2432 KB Output is correct
8 Correct 2 ms 2432 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 2 ms 2560 KB Output is correct
11 Correct 3 ms 2560 KB Output is correct
12 Correct 3 ms 2432 KB Output is correct
13 Correct 2 ms 2432 KB Output is correct
14 Correct 3 ms 2560 KB Output is correct
15 Correct 3 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Correct 2 ms 2496 KB Output is correct
3 Correct 1 ms 2432 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Correct 2 ms 2432 KB Output is correct
6 Correct 2 ms 2560 KB Output is correct
7 Correct 1 ms 2432 KB Output is correct
8 Correct 2 ms 2432 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 2 ms 2432 KB Output is correct
11 Correct 3 ms 2560 KB Output is correct
12 Correct 2 ms 2432 KB Output is correct
13 Correct 3 ms 2432 KB Output is correct
14 Correct 3 ms 2560 KB Output is correct
15 Correct 3 ms 2560 KB Output is correct
16 Correct 2 ms 2560 KB Output is correct
17 Correct 5 ms 2688 KB Output is correct
18 Correct 3 ms 2560 KB Output is correct
19 Correct 2 ms 2560 KB Output is correct
20 Correct 4 ms 2560 KB Output is correct
21 Correct 2 ms 2560 KB Output is correct
22 Correct 2 ms 2560 KB Output is correct
23 Correct 3 ms 2560 KB Output is correct
24 Correct 4 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 3 ms 2560 KB Output is correct
27 Correct 4 ms 2560 KB Output is correct
28 Correct 4 ms 2816 KB Output is correct
29 Correct 4 ms 3200 KB Output is correct
30 Correct 3 ms 2816 KB Output is correct
31 Correct 3 ms 2944 KB Output is correct
32 Correct 3 ms 2816 KB Output is correct
33 Correct 7 ms 3968 KB Output is correct
34 Correct 6 ms 3840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 1 ms 2432 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Correct 2 ms 2432 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 1 ms 2432 KB Output is correct
8 Correct 2 ms 2432 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 2 ms 2432 KB Output is correct
11 Correct 4 ms 2560 KB Output is correct
12 Correct 2 ms 2432 KB Output is correct
13 Correct 3 ms 2432 KB Output is correct
14 Correct 3 ms 2560 KB Output is correct
15 Correct 3 ms 2560 KB Output is correct
16 Correct 3 ms 2560 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 3 ms 2560 KB Output is correct
19 Correct 2 ms 2560 KB Output is correct
20 Correct 3 ms 2560 KB Output is correct
21 Correct 3 ms 2560 KB Output is correct
22 Correct 3 ms 2560 KB Output is correct
23 Correct 3 ms 2560 KB Output is correct
24 Correct 5 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 4 ms 2640 KB Output is correct
27 Correct 4 ms 2560 KB Output is correct
28 Correct 4 ms 2816 KB Output is correct
29 Correct 7 ms 3200 KB Output is correct
30 Correct 3 ms 2816 KB Output is correct
31 Correct 3 ms 2944 KB Output is correct
32 Correct 4 ms 2816 KB Output is correct
33 Correct 7 ms 3840 KB Output is correct
34 Correct 8 ms 3840 KB Output is correct
35 Correct 31 ms 4856 KB Output is correct
36 Correct 8 ms 2816 KB Output is correct
37 Correct 32 ms 5624 KB Output is correct
38 Correct 40 ms 5884 KB Output is correct
39 Correct 38 ms 5880 KB Output is correct
40 Correct 41 ms 5880 KB Output is correct
41 Correct 39 ms 5880 KB Output is correct
42 Correct 20 ms 2816 KB Output is correct
43 Correct 21 ms 2704 KB Output is correct
44 Correct 20 ms 2808 KB Output is correct
45 Correct 43 ms 8496 KB Output is correct
46 Correct 45 ms 8440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2432 KB Output is correct
2 Correct 2 ms 2432 KB Output is correct
3 Correct 1 ms 2432 KB Output is correct
4 Correct 2 ms 2432 KB Output is correct
5 Correct 2 ms 2432 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2432 KB Output is correct
8 Correct 2 ms 2432 KB Output is correct
9 Correct 2 ms 2432 KB Output is correct
10 Correct 2 ms 2432 KB Output is correct
11 Correct 4 ms 2560 KB Output is correct
12 Correct 3 ms 2432 KB Output is correct
13 Correct 3 ms 2432 KB Output is correct
14 Correct 3 ms 2560 KB Output is correct
15 Correct 3 ms 2560 KB Output is correct
16 Correct 3 ms 2560 KB Output is correct
17 Correct 4 ms 2688 KB Output is correct
18 Correct 3 ms 2560 KB Output is correct
19 Correct 3 ms 2560 KB Output is correct
20 Correct 3 ms 2560 KB Output is correct
21 Correct 4 ms 2560 KB Output is correct
22 Correct 2 ms 2560 KB Output is correct
23 Correct 4 ms 2560 KB Output is correct
24 Correct 6 ms 2688 KB Output is correct
25 Correct 4 ms 2688 KB Output is correct
26 Correct 5 ms 2560 KB Output is correct
27 Correct 5 ms 2560 KB Output is correct
28 Correct 4 ms 2816 KB Output is correct
29 Correct 4 ms 3200 KB Output is correct
30 Correct 3 ms 2816 KB Output is correct
31 Correct 4 ms 2944 KB Output is correct
32 Correct 3 ms 2816 KB Output is correct
33 Correct 7 ms 3840 KB Output is correct
34 Correct 6 ms 3840 KB Output is correct
35 Correct 32 ms 4856 KB Output is correct
36 Correct 6 ms 2816 KB Output is correct
37 Correct 28 ms 5632 KB Output is correct
38 Correct 38 ms 5880 KB Output is correct
39 Correct 39 ms 5880 KB Output is correct
40 Correct 39 ms 5880 KB Output is correct
41 Correct 41 ms 5880 KB Output is correct
42 Correct 20 ms 2816 KB Output is correct
43 Correct 20 ms 2688 KB Output is correct
44 Correct 20 ms 2816 KB Output is correct
45 Correct 38 ms 8440 KB Output is correct
46 Correct 39 ms 8440 KB Output is correct
47 Correct 56 ms 12792 KB Output is correct
48 Correct 33 ms 6268 KB Output is correct
49 Correct 33 ms 5240 KB Output is correct
50 Correct 20 ms 4864 KB Output is correct
51 Correct 59 ms 8196 KB Output is correct
52 Correct 52 ms 8764 KB Output is correct
53 Correct 39 ms 5364 KB Output is correct
54 Correct 4 ms 3064 KB Output is correct
55 Correct 5 ms 3580 KB Output is correct
56 Correct 28 ms 5120 KB Output is correct
57 Correct 19 ms 11392 KB Output is correct
58 Correct 17 ms 3832 KB Output is correct
59 Correct 25 ms 4212 KB Output is correct
60 Correct 25 ms 4860 KB Output is correct
61 Correct 29 ms 4352 KB Output is correct
62 Correct 43 ms 9404 KB Output is correct
63 Correct 84 ms 25588 KB Output is correct
64 Correct 92 ms 28488 KB Output is correct
65 Correct 113 ms 38388 KB Output is correct
66 Correct 195 ms 65764 KB Output is correct
67 Correct 169 ms 65508 KB Output is correct