Submission #441700

# Submission time Handle Problem Language Result Execution time Memory
441700 2021-07-05T20:50:34 Z dutch Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
161 ms 73184 KB
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 3e4, INF = 2e9;
vector<array<int, 2>> g[MAXN*2];
 
signed main(){
	cin.tie(0)->sync_with_stdio(0);
	int n, m, b, p; cin >> n >> m;
 
	int s, t;
	for(int j=0; j<m; ++j){
		cin >> b >> p;
		if(j == 0) s = b;
		if(j == 1) t = b;
		if(p == 1){
			g[b+b].push_back({b+b+p, 0});
		}else{
			for(int i=b%p; i<n; i+=p) g[b+b].push_back({i*2, abs(b-i)/p});
		}
	}
 
	for(int i=0; i<n; ++i){
		int u = i * 2;
		g[u+1].push_back({u, 0});
		if(i-1 >= 0) g[u+1].push_back({u-1, 1});
		if(i+1 <  n) g[u+1].push_back({u+3, 1});
	}
 
	priority_queue<array<int, 2>> q;
	int d[n*2]; fill(d, d+n+n, INF);
	q.push({d[s+s] = 0, s+s});
 
	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])
			if(d[v] > dist + w) q.push({-(d[v] = dist + w), v});
	}
 
	if(d[t+t] == INF) d[t+t] = -1;
	cout << d[t+t];
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:32:13: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |  q.push({d[s+s] = 0, s+s});
      |            ~^~
skyscraper.cpp:42:8: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |  if(d[t+t] == INF) d[t+t] = -1;
      |       ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 2 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 2 ms 1612 KB Output is correct
8 Correct 2 ms 1612 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 2 ms 1740 KB Output is correct
12 Correct 2 ms 1740 KB Output is correct
13 Correct 2 ms 1740 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 2 ms 1740 KB Output is correct
12 Correct 2 ms 1712 KB Output is correct
13 Correct 2 ms 1740 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 2 ms 1740 KB Output is correct
17 Correct 3 ms 1996 KB Output is correct
18 Correct 2 ms 1868 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1868 KB Output is correct
24 Correct 3 ms 1996 KB Output is correct
25 Correct 3 ms 1868 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 3 ms 1996 KB Output is correct
29 Correct 3 ms 2508 KB Output is correct
30 Correct 2 ms 1996 KB Output is correct
31 Correct 3 ms 2124 KB Output is correct
32 Correct 2 ms 1996 KB Output is correct
33 Correct 5 ms 3136 KB Output is correct
34 Correct 5 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 2 ms 1740 KB Output is correct
12 Correct 2 ms 1740 KB Output is correct
13 Correct 2 ms 1744 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 1 ms 1740 KB Output is correct
17 Correct 3 ms 2000 KB Output is correct
18 Correct 2 ms 1868 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1868 KB Output is correct
24 Correct 3 ms 1996 KB Output is correct
25 Correct 3 ms 1868 KB Output is correct
26 Correct 3 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 3 ms 1996 KB Output is correct
29 Correct 4 ms 2508 KB Output is correct
30 Correct 2 ms 1996 KB Output is correct
31 Correct 3 ms 2124 KB Output is correct
32 Correct 2 ms 1996 KB Output is correct
33 Correct 6 ms 3020 KB Output is correct
34 Correct 5 ms 3020 KB Output is correct
35 Correct 11 ms 3340 KB Output is correct
36 Correct 3 ms 1996 KB Output is correct
37 Correct 12 ms 4948 KB Output is correct
38 Correct 13 ms 4492 KB Output is correct
39 Correct 15 ms 4604 KB Output is correct
40 Correct 14 ms 4504 KB Output is correct
41 Correct 14 ms 4456 KB Output is correct
42 Correct 7 ms 2204 KB Output is correct
43 Correct 7 ms 2124 KB Output is correct
44 Correct 7 ms 2036 KB Output is correct
45 Correct 16 ms 6820 KB Output is correct
46 Correct 16 ms 6872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1612 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 1 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 1 ms 1612 KB Output is correct
6 Correct 1 ms 1612 KB Output is correct
7 Correct 1 ms 1612 KB Output is correct
8 Correct 1 ms 1612 KB Output is correct
9 Correct 1 ms 1612 KB Output is correct
10 Correct 1 ms 1740 KB Output is correct
11 Correct 2 ms 1740 KB Output is correct
12 Correct 1 ms 1740 KB Output is correct
13 Correct 2 ms 1740 KB Output is correct
14 Correct 2 ms 1740 KB Output is correct
15 Correct 2 ms 1740 KB Output is correct
16 Correct 2 ms 1740 KB Output is correct
17 Correct 3 ms 1996 KB Output is correct
18 Correct 2 ms 1868 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 2 ms 1868 KB Output is correct
21 Correct 2 ms 1740 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 3 ms 1868 KB Output is correct
24 Correct 3 ms 1996 KB Output is correct
25 Correct 3 ms 1868 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 3 ms 1996 KB Output is correct
29 Correct 4 ms 2508 KB Output is correct
30 Correct 2 ms 1996 KB Output is correct
31 Correct 3 ms 2124 KB Output is correct
32 Correct 2 ms 1996 KB Output is correct
33 Correct 5 ms 3020 KB Output is correct
34 Correct 5 ms 3020 KB Output is correct
35 Correct 10 ms 3404 KB Output is correct
36 Correct 3 ms 1996 KB Output is correct
37 Correct 12 ms 4940 KB Output is correct
38 Correct 14 ms 4428 KB Output is correct
39 Correct 14 ms 4556 KB Output is correct
40 Correct 14 ms 4556 KB Output is correct
41 Correct 14 ms 4464 KB Output is correct
42 Correct 7 ms 2124 KB Output is correct
43 Correct 7 ms 2160 KB Output is correct
44 Correct 7 ms 2036 KB Output is correct
45 Correct 16 ms 6860 KB Output is correct
46 Correct 17 ms 6840 KB Output is correct
47 Correct 42 ms 12712 KB Output is correct
48 Correct 18 ms 5332 KB Output is correct
49 Correct 16 ms 4816 KB Output is correct
50 Correct 13 ms 4824 KB Output is correct
51 Correct 38 ms 7360 KB Output is correct
52 Correct 47 ms 7524 KB Output is correct
53 Correct 24 ms 4580 KB Output is correct
54 Correct 9 ms 3788 KB Output is correct
55 Correct 9 ms 3812 KB Output is correct
56 Correct 15 ms 4300 KB Output is correct
57 Correct 148 ms 61160 KB Output is correct
58 Correct 14 ms 4132 KB Output is correct
59 Correct 17 ms 4760 KB Output is correct
60 Correct 18 ms 5452 KB Output is correct
61 Correct 17 ms 4628 KB Output is correct
62 Correct 32 ms 8636 KB Output is correct
63 Correct 64 ms 25900 KB Output is correct
64 Correct 77 ms 34492 KB Output is correct
65 Correct 101 ms 40652 KB Output is correct
66 Correct 161 ms 72188 KB Output is correct
67 Correct 161 ms 73184 KB Output is correct