답안 #953960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953960 2024-03-27T02:10:24 Z JooDdae Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
246 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int INF = 1e9;

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

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	for(int i=1;i<=m;i++) {
		cin >> s[i] >> p[i];
		st[s[i]].insert(p[i]);
	}
	for(int i=1;i<=m;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[1]] = 0, pq.push({0, s[1]});
	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[2]] == INF ? -1 : d[s[2]]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2804 KB Output is correct
2 Correct 1 ms 2480 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 2 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 2 ms 2652 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2808 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 4 ms 4820 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2700 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 4 ms 4820 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 2 ms 2708 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 2 ms 2912 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 1 ms 2652 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2912 KB Output is correct
26 Correct 49 ms 37048 KB Output is correct
27 Correct 39 ms 37316 KB Output is correct
28 Correct 2 ms 2912 KB Output is correct
29 Correct 3 ms 3416 KB Output is correct
30 Correct 2 ms 2904 KB Output is correct
31 Correct 2 ms 3168 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 4 ms 4188 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2852 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2740 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 5 ms 4820 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 2 ms 2696 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2652 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2820 KB Output is correct
26 Correct 40 ms 37576 KB Output is correct
27 Correct 38 ms 35764 KB Output is correct
28 Correct 2 ms 2904 KB Output is correct
29 Correct 3 ms 3416 KB Output is correct
30 Correct 2 ms 2904 KB Output is correct
31 Correct 2 ms 3164 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 3 ms 4188 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
35 Correct 12 ms 5424 KB Output is correct
36 Correct 3 ms 3164 KB Output is correct
37 Correct 14 ms 5976 KB Output is correct
38 Correct 16 ms 6492 KB Output is correct
39 Correct 16 ms 6492 KB Output is correct
40 Correct 16 ms 6236 KB Output is correct
41 Correct 19 ms 6236 KB Output is correct
42 Runtime error 246 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2648 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2648 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2692 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 4 ms 4820 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 1 ms 2652 KB Output is correct
17 Correct 2 ms 2908 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 1 ms 2772 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 2 ms 2908 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 39 ms 35688 KB Output is correct
27 Correct 38 ms 36524 KB Output is correct
28 Correct 1 ms 2908 KB Output is correct
29 Correct 2 ms 3420 KB Output is correct
30 Correct 2 ms 2904 KB Output is correct
31 Correct 2 ms 3164 KB Output is correct
32 Correct 2 ms 2908 KB Output is correct
33 Correct 3 ms 4040 KB Output is correct
34 Correct 4 ms 4188 KB Output is correct
35 Correct 11 ms 5304 KB Output is correct
36 Correct 2 ms 3164 KB Output is correct
37 Correct 14 ms 6236 KB Output is correct
38 Correct 16 ms 6492 KB Output is correct
39 Correct 16 ms 6492 KB Output is correct
40 Correct 16 ms 6488 KB Output is correct
41 Correct 16 ms 6232 KB Output is correct
42 Runtime error 227 ms 262144 KB Execution killed with signal 9
43 Halted 0 ms 0 KB -