Submission #953964

# Submission time Handle Problem Language Result Execution time Memory
953964 2024-03-27T02:24:12 Z JooDdae Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
149 ms 81592 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll INF = 1e18;

int n, m, s[30030], p[30030];
ll d[30030];
vector<array<int, 2>> v[30030];
set<int> st[30030], did[30030];
priority_queue<array<int, 2>> pq;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	for(int i=0;i<m;i++) {
		cin >> s[i] >> p[i];
		st[s[i]].insert(p[i]);
	}
	for(int i=0;i<m;i++) {
		if(did[s[i]].count(p[i])) continue;
		did[s[i]].insert(p[i]);
		for(int j=1;;j++) {
			int x = s[i]-p[i]*j;
			if(x < 0) break;
			v[s[i]].push_back({x, j});
			if(st[x].count(p[i])) break;
		}
		for(int j=1;;j++) {
			int x = s[i]+p[i]*j;
			if(x >= n) break;
			v[s[i]].push_back({x, j});
			if(st[x].count(p[i])) break;
		}
	}
	fill(d, d+n, INF);
	d[s[0]] = 0, pq.push({0, s[0]});
	while(!pq.empty()) {
		auto [c, u] = pq.top(); pq.pop();
		if(-c > d[u]) continue;
		for(auto [x, y] : v[u]) if(y-c < d[x]) d[x] = y-c, pq.push({c-y, x});
	}
	cout << (d[s[1]] == INF ? -1 : d[s[1]]);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3932 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Correct 1 ms 3932 KB Output is correct
4 Correct 1 ms 3996 KB Output is correct
5 Correct 2 ms 3932 KB Output is correct
6 Correct 2 ms 3932 KB Output is correct
7 Correct 1 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3932 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 2 ms 3928 KB Output is correct
5 Correct 1 ms 3932 KB Output is correct
6 Correct 1 ms 3932 KB Output is correct
7 Correct 1 ms 3988 KB Output is correct
8 Correct 1 ms 3932 KB Output is correct
9 Correct 2 ms 3928 KB Output is correct
10 Correct 2 ms 3932 KB Output is correct
11 Correct 2 ms 4184 KB Output is correct
12 Correct 2 ms 3932 KB Output is correct
13 Correct 1 ms 3932 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3932 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 1 ms 3932 KB Output is correct
5 Correct 1 ms 3932 KB Output is correct
6 Correct 1 ms 3932 KB Output is correct
7 Correct 2 ms 3928 KB Output is correct
8 Correct 2 ms 3932 KB Output is correct
9 Correct 1 ms 3936 KB Output is correct
10 Correct 2 ms 4008 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 1 ms 3932 KB Output is correct
13 Correct 2 ms 3928 KB Output is correct
14 Correct 2 ms 4216 KB Output is correct
15 Correct 3 ms 4176 KB Output is correct
16 Correct 2 ms 3932 KB Output is correct
17 Correct 2 ms 4188 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 3932 KB Output is correct
20 Correct 2 ms 4188 KB Output is correct
21 Correct 2 ms 3932 KB Output is correct
22 Correct 2 ms 3992 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 2 ms 4188 KB Output is correct
25 Correct 3 ms 4364 KB Output is correct
26 Correct 2 ms 3952 KB Output is correct
27 Correct 3 ms 4184 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 3 ms 4700 KB Output is correct
30 Correct 2 ms 4188 KB Output is correct
31 Correct 3 ms 4444 KB Output is correct
32 Correct 2 ms 4188 KB Output is correct
33 Correct 6 ms 5468 KB Output is correct
34 Correct 5 ms 5468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3932 KB Output is correct
2 Correct 1 ms 3932 KB Output is correct
3 Correct 1 ms 3932 KB Output is correct
4 Correct 2 ms 3932 KB Output is correct
5 Correct 1 ms 3932 KB Output is correct
6 Correct 2 ms 3932 KB Output is correct
7 Correct 2 ms 3932 KB Output is correct
8 Correct 1 ms 3932 KB Output is correct
9 Correct 1 ms 3932 KB Output is correct
10 Correct 1 ms 3932 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 3928 KB Output is correct
13 Correct 2 ms 3932 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 2 ms 3932 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 2 ms 4188 KB Output is correct
19 Correct 2 ms 3928 KB Output is correct
20 Correct 2 ms 4188 KB Output is correct
21 Correct 2 ms 3932 KB Output is correct
22 Correct 2 ms 3932 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 3 ms 4380 KB Output is correct
25 Correct 3 ms 4188 KB Output is correct
26 Correct 2 ms 3928 KB Output is correct
27 Correct 2 ms 3932 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 4 ms 4732 KB Output is correct
30 Correct 2 ms 4188 KB Output is correct
31 Correct 4 ms 4444 KB Output is correct
32 Correct 3 ms 4188 KB Output is correct
33 Correct 5 ms 5548 KB Output is correct
34 Correct 5 ms 5468 KB Output is correct
35 Correct 16 ms 7772 KB Output is correct
36 Correct 4 ms 4696 KB Output is correct
37 Correct 18 ms 8096 KB Output is correct
38 Correct 21 ms 8856 KB Output is correct
39 Correct 21 ms 9036 KB Output is correct
40 Correct 26 ms 9044 KB Output is correct
41 Correct 21 ms 9000 KB Output is correct
42 Correct 5 ms 4444 KB Output is correct
43 Correct 6 ms 4444 KB Output is correct
44 Correct 5 ms 4440 KB Output is correct
45 Correct 23 ms 11684 KB Output is correct
46 Correct 23 ms 11612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4188 KB Output is correct
2 Correct 1 ms 4128 KB Output is correct
3 Correct 1 ms 3932 KB Output is correct
4 Correct 1 ms 3936 KB Output is correct
5 Correct 1 ms 3932 KB Output is correct
6 Correct 1 ms 3932 KB Output is correct
7 Correct 1 ms 3936 KB Output is correct
8 Correct 1 ms 3932 KB Output is correct
9 Correct 1 ms 3936 KB Output is correct
10 Correct 2 ms 3936 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 3944 KB Output is correct
13 Correct 2 ms 3936 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4200 KB Output is correct
16 Correct 2 ms 3936 KB Output is correct
17 Correct 4 ms 4192 KB Output is correct
18 Correct 2 ms 4192 KB Output is correct
19 Correct 2 ms 3940 KB Output is correct
20 Correct 2 ms 4220 KB Output is correct
21 Correct 2 ms 3944 KB Output is correct
22 Correct 2 ms 3940 KB Output is correct
23 Correct 2 ms 4192 KB Output is correct
24 Correct 2 ms 4196 KB Output is correct
25 Correct 2 ms 4192 KB Output is correct
26 Correct 2 ms 4192 KB Output is correct
27 Correct 2 ms 3944 KB Output is correct
28 Correct 2 ms 4444 KB Output is correct
29 Correct 4 ms 4704 KB Output is correct
30 Correct 2 ms 4248 KB Output is correct
31 Correct 2 ms 4456 KB Output is correct
32 Correct 2 ms 4196 KB Output is correct
33 Correct 4 ms 5476 KB Output is correct
34 Correct 5 ms 5476 KB Output is correct
35 Correct 17 ms 7792 KB Output is correct
36 Correct 4 ms 4708 KB Output is correct
37 Correct 23 ms 8144 KB Output is correct
38 Correct 25 ms 9040 KB Output is correct
39 Correct 21 ms 9052 KB Output is correct
40 Correct 23 ms 9040 KB Output is correct
41 Correct 25 ms 8856 KB Output is correct
42 Correct 5 ms 4532 KB Output is correct
43 Correct 5 ms 4448 KB Output is correct
44 Correct 5 ms 4708 KB Output is correct
45 Correct 24 ms 11620 KB Output is correct
46 Correct 23 ms 11624 KB Output is correct
47 Correct 39 ms 15848 KB Output is correct
48 Correct 15 ms 8932 KB Output is correct
49 Correct 16 ms 8032 KB Output is correct
50 Correct 10 ms 7268 KB Output is correct
51 Correct 35 ms 11304 KB Output is correct
52 Correct 35 ms 12408 KB Output is correct
53 Correct 17 ms 8984 KB Output is correct
54 Correct 3 ms 4700 KB Output is correct
55 Correct 4 ms 5016 KB Output is correct
56 Correct 11 ms 8284 KB Output is correct
57 Correct 30 ms 13232 KB Output is correct
58 Correct 8 ms 5528 KB Output is correct
59 Correct 8 ms 5860 KB Output is correct
60 Correct 9 ms 6668 KB Output is correct
61 Correct 10 ms 6172 KB Output is correct
62 Correct 20 ms 12504 KB Output is correct
63 Correct 66 ms 32012 KB Output is correct
64 Correct 68 ms 40956 KB Output is correct
65 Correct 87 ms 52260 KB Output is correct
66 Correct 149 ms 81592 KB Output is correct
67 Correct 135 ms 80652 KB Output is correct