Submission #972116

# Submission time Handle Problem Language Result Execution time Memory
972116 2024-04-30T06:23:54 Z Halym2007 Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
163 ms 66912 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define pii pair <int, int>
const int N = 3e4 + 5;

map <int, bool> m[N];
vector <pii> v[N];
vector <int> q[N];
int n, k, dis[N], a[N], b[N];

priority_queue <pii, vector <pii>, greater <pii>> p;

int main () {
//	freopen ("input.txt", "r", stdin);
	cin >> n >> k;
	for (int i = 0; i < k; ++i) {
		cin >> a[i] >> b[i];
		if (m[a[i]].find (b[i]) == m[a[i]].end()) {
			q[a[i]].pb (b[i]);
			m[a[i]][b[i]] = 1;
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j : q[i]) {
			int val = i + j;
			int bal = 1;
			while (val < n) {
				v[i].pb ({val, bal});
				if (m[val].find (j) != m[val].end()) {
					break;
				}
				bal++;
				val += j;
			}
			val = i - j;
			bal = 1;
			while (val >= 0) {
				v[i].pb ({val, bal});
				if (m[val].find (j) != m[val].end()) {
					break;
				}
				bal++;
				val -= j;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		dis[i] = 1e9;
	}
	int jj = a[0], jj1 = a[1];
	p.push ({0, jj});
	dis[jj] = 0;
	while (!p.empty()) {
		int x = p.top().ss;
		p.pop();
		for (pii i : v[x]) {
			if (dis[i.ff] > dis[x] + i.ss) {
				dis[i.ff] = dis[x] + i.ss;
				p.push({dis[i.ff], i.ff});
			}
		}
	}
	if (dis[jj1] == 1e9) dis[jj1] = -1;
//	cout << jj << " " << jj1 << " ";
	cout << dis[jj1];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3620 KB Output is correct
4 Correct 1 ms 3416 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 2 ms 3576 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 2 ms 3420 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3416 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
8 Correct 1 ms 3416 KB Output is correct
9 Correct 1 ms 3420 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 1 ms 3420 KB Output is correct
13 Correct 2 ms 3672 KB Output is correct
14 Correct 2 ms 3416 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 2 ms 3420 KB Output is correct
17 Correct 2 ms 3676 KB Output is correct
18 Correct 2 ms 3624 KB Output is correct
19 Correct 1 ms 3440 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3416 KB Output is correct
22 Correct 2 ms 3420 KB Output is correct
23 Correct 2 ms 3508 KB Output is correct
24 Correct 3 ms 3676 KB Output is correct
25 Correct 3 ms 3676 KB Output is correct
26 Correct 2 ms 3420 KB Output is correct
27 Correct 2 ms 3416 KB Output is correct
28 Correct 3 ms 3676 KB Output is correct
29 Correct 4 ms 4440 KB Output is correct
30 Correct 2 ms 3672 KB Output is correct
31 Correct 2 ms 3676 KB Output is correct
32 Correct 2 ms 3672 KB Output is correct
33 Correct 5 ms 4784 KB Output is correct
34 Correct 5 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Correct 1 ms 3416 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3416 KB Output is correct
7 Correct 1 ms 3416 KB Output is correct
8 Correct 1 ms 3420 KB Output is correct
9 Correct 1 ms 3416 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 3 ms 3504 KB Output is correct
12 Correct 3 ms 3420 KB Output is correct
13 Correct 2 ms 3672 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 2 ms 3672 KB Output is correct
16 Correct 1 ms 3420 KB Output is correct
17 Correct 2 ms 3676 KB Output is correct
18 Correct 2 ms 3420 KB Output is correct
19 Correct 1 ms 3416 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3420 KB Output is correct
22 Correct 2 ms 3420 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 3 ms 3676 KB Output is correct
25 Correct 3 ms 3676 KB Output is correct
26 Correct 2 ms 3420 KB Output is correct
27 Correct 3 ms 3420 KB Output is correct
28 Correct 4 ms 3932 KB Output is correct
29 Correct 3 ms 4188 KB Output is correct
30 Correct 2 ms 3676 KB Output is correct
31 Correct 2 ms 3928 KB Output is correct
32 Correct 2 ms 3676 KB Output is correct
33 Correct 5 ms 4688 KB Output is correct
34 Correct 5 ms 4700 KB Output is correct
35 Correct 22 ms 6236 KB Output is correct
36 Correct 4 ms 3932 KB Output is correct
37 Correct 19 ms 6812 KB Output is correct
38 Correct 25 ms 7272 KB Output is correct
39 Correct 27 ms 7220 KB Output is correct
40 Correct 24 ms 7252 KB Output is correct
41 Correct 24 ms 7248 KB Output is correct
42 Correct 11 ms 3928 KB Output is correct
43 Correct 12 ms 3676 KB Output is correct
44 Correct 11 ms 3932 KB Output is correct
45 Correct 23 ms 9632 KB Output is correct
46 Correct 27 ms 9552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3416 KB Output is correct
4 Correct 1 ms 3420 KB Output is correct
5 Correct 1 ms 3420 KB Output is correct
6 Correct 1 ms 3420 KB Output is correct
7 Correct 1 ms 3420 KB Output is correct
8 Correct 1 ms 3416 KB Output is correct
9 Correct 1 ms 3416 KB Output is correct
10 Correct 1 ms 3420 KB Output is correct
11 Correct 2 ms 3420 KB Output is correct
12 Correct 1 ms 3416 KB Output is correct
13 Correct 2 ms 3420 KB Output is correct
14 Correct 2 ms 3420 KB Output is correct
15 Correct 2 ms 3696 KB Output is correct
16 Correct 2 ms 3416 KB Output is correct
17 Correct 2 ms 3676 KB Output is correct
18 Correct 2 ms 3420 KB Output is correct
19 Correct 1 ms 3416 KB Output is correct
20 Correct 2 ms 3676 KB Output is correct
21 Correct 2 ms 3420 KB Output is correct
22 Correct 1 ms 3420 KB Output is correct
23 Correct 2 ms 3420 KB Output is correct
24 Correct 3 ms 3676 KB Output is correct
25 Correct 3 ms 3676 KB Output is correct
26 Correct 2 ms 3420 KB Output is correct
27 Correct 2 ms 3420 KB Output is correct
28 Correct 2 ms 3660 KB Output is correct
29 Correct 3 ms 4188 KB Output is correct
30 Correct 2 ms 3676 KB Output is correct
31 Correct 3 ms 3676 KB Output is correct
32 Correct 2 ms 3676 KB Output is correct
33 Correct 5 ms 4700 KB Output is correct
34 Correct 5 ms 4700 KB Output is correct
35 Correct 19 ms 6100 KB Output is correct
36 Correct 4 ms 3932 KB Output is correct
37 Correct 19 ms 6736 KB Output is correct
38 Correct 24 ms 7252 KB Output is correct
39 Correct 24 ms 7244 KB Output is correct
40 Correct 24 ms 7248 KB Output is correct
41 Correct 27 ms 7572 KB Output is correct
42 Correct 11 ms 3928 KB Output is correct
43 Correct 11 ms 3672 KB Output is correct
44 Correct 10 ms 3928 KB Output is correct
45 Correct 25 ms 9564 KB Output is correct
46 Correct 25 ms 9548 KB Output is correct
47 Correct 42 ms 14236 KB Output is correct
48 Correct 20 ms 7628 KB Output is correct
49 Correct 19 ms 6488 KB Output is correct
50 Correct 14 ms 6232 KB Output is correct
51 Correct 40 ms 9936 KB Output is correct
52 Correct 46 ms 10152 KB Output is correct
53 Correct 25 ms 7376 KB Output is correct
54 Correct 4 ms 3932 KB Output is correct
55 Correct 4 ms 4312 KB Output is correct
56 Correct 21 ms 7000 KB Output is correct
57 Correct 30 ms 12512 KB Output is correct
58 Correct 11 ms 4564 KB Output is correct
59 Correct 15 ms 5080 KB Output is correct
60 Correct 15 ms 5844 KB Output is correct
61 Correct 16 ms 5088 KB Output is correct
62 Correct 31 ms 11472 KB Output is correct
63 Correct 67 ms 26828 KB Output is correct
64 Correct 73 ms 30152 KB Output is correct
65 Correct 92 ms 40904 KB Output is correct
66 Correct 155 ms 66412 KB Output is correct
67 Correct 163 ms 66912 KB Output is correct