Submission #518415

# Submission time Handle Problem Language Result Execution time Memory
518415 2022-01-23T18:10:47 Z CodeTiger927 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
331 ms 112556 KB
using namespace std;

#include <iostream>
#include <bitset>
#include <queue>
#include <vector>

#define MAXN 30005

int N,M,pos[MAXN],po[MAXN];
bitset<MAXN> vis[MAXN],vis2;
queue<pair<int,pair<int,int>>> q;
vector<int> v[MAXN];

void insert(int dist,int x,int p) {
	if(~p && !vis[x][p]) {
		vis[x][p] = true;
		q.push({dist,{x,p}});
	}
	if(vis2[x]) return;
	vis2[x] = true;
	for(int u : v[x]) {
		if(vis[x][u]) continue;
		vis[x][u] = true;
		q.push({dist,{x,u}});
	}
	return;
}

bool within(int n) {
	return (n >= 0 && n < N);
}

int main() {
	cin >> N >> M;
	for(int i = 0;i < M;++i) {
		cin >> pos[i] >> po[i];
		v[pos[i]].push_back(po[i]);
	}
	insert(0,pos[0],-1);
	while(!q.empty()) {
		auto [u,v] = q.front();
		auto [a,b] = v;
		q.pop();
		if(a == pos[1]) {
			cout << u << endl;
			return 0;
		}
		if(within(a - b)) insert(u + 1,a - b,b);
		if(within(a + b)) insert(u + 1,a + b,b);
	}
	cout << -1 << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 2 ms 1124 KB Output is correct
10 Correct 1 ms 1228 KB Output is correct
11 Correct 2 ms 1256 KB Output is correct
12 Correct 2 ms 1276 KB Output is correct
13 Correct 2 ms 1404 KB Output is correct
14 Correct 2 ms 1404 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1264 KB Output is correct
11 Correct 2 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1308 KB Output is correct
14 Correct 2 ms 1356 KB Output is correct
15 Correct 2 ms 1384 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 3 ms 3788 KB Output is correct
18 Correct 1 ms 1024 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 6 ms 8396 KB Output is correct
21 Correct 1 ms 1024 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 4 ms 6268 KB Output is correct
24 Correct 6 ms 7560 KB Output is correct
25 Correct 3 ms 2372 KB Output is correct
26 Correct 5 ms 7372 KB Output is correct
27 Correct 5 ms 7680 KB Output is correct
28 Correct 7 ms 8348 KB Output is correct
29 Correct 6 ms 8396 KB Output is correct
30 Correct 6 ms 8312 KB Output is correct
31 Correct 5 ms 8268 KB Output is correct
32 Correct 7 ms 8268 KB Output is correct
33 Correct 9 ms 8396 KB Output is correct
34 Correct 7 ms 8396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 1 ms 1248 KB Output is correct
11 Correct 2 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1388 KB Output is correct
14 Correct 2 ms 1404 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 1028 KB Output is correct
17 Correct 3 ms 3800 KB Output is correct
18 Correct 1 ms 1040 KB Output is correct
19 Correct 1 ms 1032 KB Output is correct
20 Correct 6 ms 8364 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 5 ms 6360 KB Output is correct
24 Correct 5 ms 7556 KB Output is correct
25 Correct 2 ms 2508 KB Output is correct
26 Correct 5 ms 7372 KB Output is correct
27 Correct 5 ms 7684 KB Output is correct
28 Correct 6 ms 8396 KB Output is correct
29 Correct 7 ms 8396 KB Output is correct
30 Correct 6 ms 8268 KB Output is correct
31 Correct 6 ms 8304 KB Output is correct
32 Correct 6 ms 8268 KB Output is correct
33 Correct 9 ms 8396 KB Output is correct
34 Correct 8 ms 8396 KB Output is correct
35 Correct 17 ms 7300 KB Output is correct
36 Correct 4 ms 3020 KB Output is correct
37 Correct 14 ms 8824 KB Output is correct
38 Correct 25 ms 9412 KB Output is correct
39 Correct 16 ms 2252 KB Output is correct
40 Correct 23 ms 4548 KB Output is correct
41 Correct 27 ms 8808 KB Output is correct
42 Correct 16 ms 7976 KB Output is correct
43 Correct 16 ms 8268 KB Output is correct
44 Correct 16 ms 8964 KB Output is correct
45 Correct 29 ms 9352 KB Output is correct
46 Correct 28 ms 9332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 2 ms 1228 KB Output is correct
11 Correct 2 ms 1356 KB Output is correct
12 Correct 2 ms 1356 KB Output is correct
13 Correct 2 ms 1356 KB Output is correct
14 Correct 2 ms 1404 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 972 KB Output is correct
17 Correct 5 ms 3788 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 5 ms 8396 KB Output is correct
21 Correct 1 ms 1040 KB Output is correct
22 Correct 1 ms 1036 KB Output is correct
23 Correct 5 ms 6268 KB Output is correct
24 Correct 6 ms 7500 KB Output is correct
25 Correct 3 ms 2432 KB Output is correct
26 Correct 6 ms 7372 KB Output is correct
27 Correct 5 ms 7672 KB Output is correct
28 Correct 7 ms 8456 KB Output is correct
29 Correct 6 ms 8396 KB Output is correct
30 Correct 5 ms 8268 KB Output is correct
31 Correct 6 ms 8352 KB Output is correct
32 Correct 5 ms 8268 KB Output is correct
33 Correct 8 ms 8396 KB Output is correct
34 Correct 7 ms 8396 KB Output is correct
35 Correct 15 ms 7172 KB Output is correct
36 Correct 4 ms 3020 KB Output is correct
37 Correct 15 ms 8844 KB Output is correct
38 Correct 21 ms 9396 KB Output is correct
39 Correct 16 ms 2180 KB Output is correct
40 Correct 17 ms 4608 KB Output is correct
41 Correct 20 ms 8780 KB Output is correct
42 Correct 16 ms 8012 KB Output is correct
43 Correct 18 ms 8356 KB Output is correct
44 Correct 17 ms 9012 KB Output is correct
45 Correct 36 ms 9352 KB Output is correct
46 Correct 23 ms 9348 KB Output is correct
47 Correct 33 ms 32248 KB Output is correct
48 Correct 13 ms 1844 KB Output is correct
49 Correct 13 ms 1792 KB Output is correct
50 Correct 9 ms 1596 KB Output is correct
51 Correct 68 ms 87544 KB Output is correct
52 Correct 74 ms 94256 KB Output is correct
53 Correct 27 ms 18928 KB Output is correct
54 Correct 34 ms 61160 KB Output is correct
55 Correct 44 ms 77820 KB Output is correct
56 Correct 75 ms 112404 KB Output is correct
57 Correct 3 ms 2692 KB Output is correct
58 Correct 78 ms 111800 KB Output is correct
59 Correct 77 ms 104084 KB Output is correct
60 Correct 71 ms 104056 KB Output is correct
61 Correct 74 ms 99016 KB Output is correct
62 Correct 121 ms 112556 KB Output is correct
63 Correct 172 ms 111964 KB Output is correct
64 Correct 168 ms 111944 KB Output is correct
65 Correct 213 ms 112128 KB Output is correct
66 Correct 331 ms 112152 KB Output is correct
67 Correct 207 ms 112068 KB Output is correct