Submission #244799

# Submission time Handle Problem Language Result Execution time Memory
244799 2020-07-05T04:30:12 Z vioalbert Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
231 ms 67172 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 3e4+5, MAX = 2e9;
int n, m, batas;
vector<pair<int, int>> adj[N];
set<int> power[N];
int location[N], p[N];

typedef pair<int, int> state;

int dijkstra(int s, int e) {
	vector<bool> vis(n+1, 0);
	vector<int> dist(n+1, MAX);
	priority_queue<state, vector<state>, greater<state>> pq;
	pq.push({0, s});
	dist[s] = 0;

	while(!pq.empty()) {
		int u = pq.top().second; pq.pop();
		if(u == e) return dist[e];
		if(!vis[u]) {
			vis[u] = 1;
			for(auto& it : adj[u]) {
				int v = it.first, d = it.second;
				if(dist[v] > dist[u] + d) {
					dist[v] = dist[u] + d;
					pq.push({dist[v], v});
				}
			}
		}
	}
	return -1;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		cin >> location[i] >> p[i];
		power[location[i]].insert(p[i]);
	}

	for(int i = 0; i < n; i++) {
		for(auto x : power[i]) {
			int lst = -1;
			for(int j = i%x; j < n; j+=x) {
				if(power[j].count(x) > 0) {
					if(lst >= 0) {
						adj[lst].push_back({j, abs(lst-j)/x});
						adj[j].push_back({lst, abs(lst-j)/x});
					}
					for(int k = j-x; k > lst; k-=x)
						adj[j].push_back({k, abs(k-j)/x});
					lst = j;
					if(i != j) power[j].erase(x);
				} else if(lst >= 0) {
					adj[lst].push_back({j, abs(lst-j)/x});
				}
			}
		}
		power[i].clear();
	}

	int ans = dijkstra(location[0], location[1]);
	cout << ans << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2560 KB Output is correct
11 Correct 6 ms 2560 KB Output is correct
12 Correct 6 ms 2432 KB Output is correct
13 Correct 6 ms 2432 KB Output is correct
14 Correct 7 ms 2688 KB Output is correct
15 Correct 7 ms 2560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 5 ms 2432 KB Output is correct
3 Correct 5 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 7 ms 2560 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 7 ms 2560 KB Output is correct
12 Correct 7 ms 2432 KB Output is correct
13 Correct 7 ms 2432 KB Output is correct
14 Correct 6 ms 2560 KB Output is correct
15 Correct 7 ms 2560 KB Output is correct
16 Correct 6 ms 2560 KB Output is correct
17 Correct 7 ms 2688 KB Output is correct
18 Correct 6 ms 2560 KB Output is correct
19 Correct 6 ms 2560 KB Output is correct
20 Correct 7 ms 2560 KB Output is correct
21 Correct 6 ms 2560 KB Output is correct
22 Correct 6 ms 2560 KB Output is correct
23 Correct 7 ms 2560 KB Output is correct
24 Correct 7 ms 2688 KB Output is correct
25 Correct 6 ms 2688 KB Output is correct
26 Correct 6 ms 2560 KB Output is correct
27 Correct 6 ms 2560 KB Output is correct
28 Correct 7 ms 2688 KB Output is correct
29 Correct 9 ms 3328 KB Output is correct
30 Correct 7 ms 2816 KB Output is correct
31 Correct 7 ms 2944 KB Output is correct
32 Correct 7 ms 2816 KB Output is correct
33 Correct 12 ms 3968 KB Output is correct
34 Correct 10 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 7 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 7 ms 2560 KB Output is correct
12 Correct 6 ms 2432 KB Output is correct
13 Correct 6 ms 2432 KB Output is correct
14 Correct 7 ms 2560 KB Output is correct
15 Correct 7 ms 2688 KB Output is correct
16 Correct 6 ms 2560 KB Output is correct
17 Correct 7 ms 2688 KB Output is correct
18 Correct 6 ms 2560 KB Output is correct
19 Correct 6 ms 2560 KB Output is correct
20 Correct 6 ms 2560 KB Output is correct
21 Correct 6 ms 2560 KB Output is correct
22 Correct 6 ms 2560 KB Output is correct
23 Correct 7 ms 2560 KB Output is correct
24 Correct 8 ms 2688 KB Output is correct
25 Correct 7 ms 2688 KB Output is correct
26 Correct 6 ms 2560 KB Output is correct
27 Correct 6 ms 2560 KB Output is correct
28 Correct 7 ms 2816 KB Output is correct
29 Correct 9 ms 3328 KB Output is correct
30 Correct 7 ms 2816 KB Output is correct
31 Correct 7 ms 2944 KB Output is correct
32 Correct 7 ms 2816 KB Output is correct
33 Correct 12 ms 3968 KB Output is correct
34 Correct 10 ms 3968 KB Output is correct
35 Correct 21 ms 4608 KB Output is correct
36 Correct 8 ms 2816 KB Output is correct
37 Correct 21 ms 5248 KB Output is correct
38 Correct 27 ms 5632 KB Output is correct
39 Correct 25 ms 5376 KB Output is correct
40 Correct 25 ms 5376 KB Output is correct
41 Correct 27 ms 5504 KB Output is correct
42 Correct 10 ms 2816 KB Output is correct
43 Correct 10 ms 2816 KB Output is correct
44 Correct 10 ms 2816 KB Output is correct
45 Correct 32 ms 8312 KB Output is correct
46 Correct 30 ms 8188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2560 KB Output is correct
11 Correct 7 ms 2560 KB Output is correct
12 Correct 6 ms 2432 KB Output is correct
13 Correct 6 ms 2432 KB Output is correct
14 Correct 7 ms 2560 KB Output is correct
15 Correct 7 ms 2688 KB Output is correct
16 Correct 6 ms 2560 KB Output is correct
17 Correct 7 ms 2688 KB Output is correct
18 Correct 7 ms 2560 KB Output is correct
19 Correct 6 ms 2560 KB Output is correct
20 Correct 6 ms 2560 KB Output is correct
21 Correct 6 ms 2560 KB Output is correct
22 Correct 6 ms 2560 KB Output is correct
23 Correct 7 ms 2560 KB Output is correct
24 Correct 7 ms 2688 KB Output is correct
25 Correct 7 ms 2688 KB Output is correct
26 Correct 6 ms 2560 KB Output is correct
27 Correct 6 ms 2560 KB Output is correct
28 Correct 7 ms 2688 KB Output is correct
29 Correct 9 ms 3328 KB Output is correct
30 Correct 7 ms 2816 KB Output is correct
31 Correct 9 ms 2944 KB Output is correct
32 Correct 7 ms 2816 KB Output is correct
33 Correct 12 ms 3968 KB Output is correct
34 Correct 11 ms 3968 KB Output is correct
35 Correct 21 ms 4608 KB Output is correct
36 Correct 8 ms 2816 KB Output is correct
37 Correct 22 ms 5248 KB Output is correct
38 Correct 29 ms 5504 KB Output is correct
39 Correct 26 ms 5504 KB Output is correct
40 Correct 26 ms 5376 KB Output is correct
41 Correct 28 ms 5496 KB Output is correct
42 Correct 10 ms 2816 KB Output is correct
43 Correct 11 ms 2816 KB Output is correct
44 Correct 10 ms 2816 KB Output is correct
45 Correct 33 ms 8312 KB Output is correct
46 Correct 34 ms 8184 KB Output is correct
47 Correct 45 ms 12404 KB Output is correct
48 Correct 23 ms 5628 KB Output is correct
49 Correct 24 ms 4736 KB Output is correct
50 Correct 16 ms 4480 KB Output is correct
51 Correct 36 ms 7436 KB Output is correct
52 Correct 40 ms 7736 KB Output is correct
53 Correct 27 ms 5116 KB Output is correct
54 Correct 7 ms 3072 KB Output is correct
55 Correct 9 ms 3452 KB Output is correct
56 Correct 18 ms 4224 KB Output is correct
57 Correct 22 ms 11392 KB Output is correct
58 Correct 14 ms 3836 KB Output is correct
59 Correct 16 ms 4240 KB Output is correct
60 Correct 16 ms 4876 KB Output is correct
61 Correct 17 ms 4100 KB Output is correct
62 Correct 32 ms 8572 KB Output is correct
63 Correct 113 ms 26092 KB Output is correct
64 Correct 97 ms 29292 KB Output is correct
65 Correct 133 ms 38892 KB Output is correct
66 Correct 231 ms 67172 KB Output is correct
67 Correct 187 ms 67044 KB Output is correct