답안 #954911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954911 2024-03-28T19:33:10 Z colossal_pepe Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 39324 KB
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

const int INF = 1e9;
const int BLK = 300;

int n, m;
vector<int> b, p;
vector<vector<int>> v;

void addDoge(int i, int pos, int d, vector<vector<int>> &dist, priority_queue<tuple<int, int, int>> &q) {
	if (p[i] < BLK and -d < dist[pos][p[i]]) {
		dist[pos][p[i]] = -d;
		q.push(make_tuple(d, pos, p[i]));
	} else {
		int l = b[i] - p[i], r = b[i] + p[i], x = 1;
		while (l >= 0 or r < n) {
			if (l >= 0 and -d + x < dist[l][0]) {
				dist[l][0] = -d + x;
				q.push(make_tuple(d - x, l, 0));
			}
			if (r < n and -d + x < dist[r][0]) {
				dist[r][0] = -d + x;
				q.push(make_tuple(d - x, r, 0));
			}
			l -= p[i];
			r += p[i];
			x++;
		}
	}
}
 
int solve() {
	vector<vector<int>> dist(n, vector<int>(BLK, INF));
	priority_queue<tuple<int, int, int>> q;
	dist[b[0]][p[0]] = 0;
	q.push(make_tuple(0, b[0], p[0]));
	while (not q.empty()) {
		auto [d, pos, power] = q.top();
		q.pop();
		if (dist[pos][power] != -d) continue;
		while (not v[pos].empty()) {
			addDoge(v[pos].back(), pos, d, dist, q);
			v[pos].pop_back();
		}
		if (power and pos + power < n and -d + 1 < dist[pos + power][power]) {
			dist[pos + power][power] = -d + 1;
			q.push(make_tuple(d - 1, pos + power, power));
		}
		if (power and pos - power >= 0 and -d + 1 < dist[pos - power][power]) {
			dist[pos - power][power] = -d + 1;
			q.push(make_tuple(d - 1, pos - power, power));
		}
	}
	int ret = INF;
	for (int i = 0; i < BLK; i++) {
		ret = min(ret, dist[b[1]][i]);
	}
	return ret == INF ? -1 : ret;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	v.resize(n), b.resize(m), p.resize(m);
	cin >> b[0] >> p[0];
	for (int i = 1; i < m; i++) {
		cin >> b[i] >> p[i];
		v[b[i]].push_back(i);
	}
	cout << solve() << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 7 ms 2908 KB Output is correct
21 Correct 1 ms 856 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2392 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 8 ms 2908 KB Output is correct
27 Correct 7 ms 2908 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 7 ms 2908 KB Output is correct
30 Correct 3 ms 2908 KB Output is correct
31 Correct 4 ms 2956 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Correct 12 ms 2908 KB Output is correct
34 Correct 12 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 7 ms 2908 KB Output is correct
21 Correct 1 ms 1112 KB Output is correct
22 Correct 1 ms 2652 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2652 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 8 ms 2980 KB Output is correct
27 Correct 7 ms 2908 KB Output is correct
28 Correct 2 ms 3008 KB Output is correct
29 Correct 6 ms 2908 KB Output is correct
30 Correct 3 ms 2908 KB Output is correct
31 Correct 4 ms 2904 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Correct 13 ms 3008 KB Output is correct
34 Correct 12 ms 2904 KB Output is correct
35 Correct 13 ms 2820 KB Output is correct
36 Correct 3 ms 1884 KB Output is correct
37 Correct 26 ms 3420 KB Output is correct
38 Correct 18 ms 3672 KB Output is correct
39 Correct 18 ms 3416 KB Output is correct
40 Correct 18 ms 3676 KB Output is correct
41 Correct 18 ms 3416 KB Output is correct
42 Correct 96 ms 3176 KB Output is correct
43 Correct 89 ms 3416 KB Output is correct
44 Correct 102 ms 3668 KB Output is correct
45 Correct 62 ms 3928 KB Output is correct
46 Correct 61 ms 4120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 2 ms 1372 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 2 ms 2908 KB Output is correct
20 Correct 8 ms 2908 KB Output is correct
21 Correct 1 ms 860 KB Output is correct
22 Correct 2 ms 2648 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 3 ms 2652 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 8 ms 2904 KB Output is correct
27 Correct 7 ms 2904 KB Output is correct
28 Correct 2 ms 2908 KB Output is correct
29 Correct 6 ms 2956 KB Output is correct
30 Correct 3 ms 2904 KB Output is correct
31 Correct 4 ms 2904 KB Output is correct
32 Correct 3 ms 2908 KB Output is correct
33 Correct 12 ms 2904 KB Output is correct
34 Correct 12 ms 2908 KB Output is correct
35 Correct 13 ms 2788 KB Output is correct
36 Correct 3 ms 1884 KB Output is correct
37 Correct 20 ms 3260 KB Output is correct
38 Correct 18 ms 3676 KB Output is correct
39 Correct 18 ms 3416 KB Output is correct
40 Correct 18 ms 3676 KB Output is correct
41 Correct 18 ms 3604 KB Output is correct
42 Correct 98 ms 3164 KB Output is correct
43 Correct 94 ms 3416 KB Output is correct
44 Correct 98 ms 3420 KB Output is correct
45 Correct 63 ms 3928 KB Output is correct
46 Correct 61 ms 4124 KB Output is correct
47 Correct 79 ms 16924 KB Output is correct
48 Correct 16 ms 30040 KB Output is correct
49 Correct 18 ms 32604 KB Output is correct
50 Correct 18 ms 35420 KB Output is correct
51 Correct 53 ms 39196 KB Output is correct
52 Correct 59 ms 39196 KB Output is correct
53 Correct 30 ms 39108 KB Output is correct
54 Correct 17 ms 37468 KB Output is correct
55 Correct 16 ms 37564 KB Output is correct
56 Execution timed out 1040 ms 39324 KB Time limit exceeded
57 Halted 0 ms 0 KB -