답안 #954899

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

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

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

int f(int x, int c, int y) {
	return x + c * y;
}

void addDoge(int i, int pos, int d, vector<vector<int>> &dist, priority_queue<tuple<int, int, int>> &q) {
	if (p[i] < BLK) {
		dist[pos][p[i]] = min(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) {
				dist[l][0] = min(dist[l][0], -d + x);
				q.push(make_tuple(d - x, l, 0));
			}
			if (r < n) {
				dist[r][0] = min(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 (pos + power < n) {
			dist[pos + power][power] = min(dist[pos + power][power], -d + 1);
			q.push(make_tuple(d - 1, pos + power, power));
		}
		if (pos - power >= 0) {
			dist[pos - power][power] = min(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 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 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 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 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 600 KB Output is correct
12 Correct 29 ms 860 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 0 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 604 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 29 ms 860 KB Output is correct
13 Correct 2 ms 608 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 4 ms 2528 KB Output is correct
18 Correct 2 ms 5212 KB Output is correct
19 Correct 2 ms 5980 KB Output is correct
20 Correct 298 ms 6184 KB Output is correct
21 Correct 1 ms 1372 KB Output is correct
22 Correct 2 ms 5468 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 5 ms 5724 KB Output is correct
25 Correct 3 ms 5976 KB Output is correct
26 Correct 471 ms 6164 KB Output is correct
27 Correct 493 ms 6232 KB Output is correct
28 Correct 4 ms 5976 KB Output is correct
29 Correct 15 ms 5980 KB Output is correct
30 Correct 5 ms 6072 KB Output is correct
31 Correct 9 ms 5976 KB Output is correct
32 Correct 7 ms 5976 KB Output is correct
33 Correct 28 ms 6236 KB Output is correct
34 Correct 28 ms 6236 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 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 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 29 ms 860 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 852 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 4 ms 2652 KB Output is correct
18 Correct 2 ms 5212 KB Output is correct
19 Correct 2 ms 5980 KB Output is correct
20 Correct 296 ms 6208 KB Output is correct
21 Correct 1 ms 1372 KB Output is correct
22 Correct 2 ms 5284 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 4 ms 5724 KB Output is correct
25 Correct 3 ms 6008 KB Output is correct
26 Correct 466 ms 6160 KB Output is correct
27 Correct 505 ms 6232 KB Output is correct
28 Correct 4 ms 5976 KB Output is correct
29 Correct 14 ms 6116 KB Output is correct
30 Correct 5 ms 6068 KB Output is correct
31 Correct 9 ms 5980 KB Output is correct
32 Correct 7 ms 6088 KB Output is correct
33 Correct 28 ms 6236 KB Output is correct
34 Correct 28 ms 6236 KB Output is correct
35 Correct 27 ms 5400 KB Output is correct
36 Correct 6 ms 3416 KB Output is correct
37 Correct 51 ms 7004 KB Output is correct
38 Correct 43 ms 7260 KB Output is correct
39 Correct 50 ms 7304 KB Output is correct
40 Correct 43 ms 7260 KB Output is correct
41 Correct 50 ms 7256 KB Output is correct
42 Execution timed out 1064 ms 7256 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 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 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 28 ms 860 KB Output is correct
13 Correct 2 ms 860 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 1 ms 856 KB Output is correct
17 Correct 4 ms 2528 KB Output is correct
18 Correct 2 ms 5212 KB Output is correct
19 Correct 3 ms 5980 KB Output is correct
20 Correct 298 ms 6168 KB Output is correct
21 Correct 1 ms 1372 KB Output is correct
22 Correct 3 ms 5628 KB Output is correct
23 Correct 3 ms 4924 KB Output is correct
24 Correct 5 ms 5724 KB Output is correct
25 Correct 3 ms 5980 KB Output is correct
26 Correct 473 ms 5976 KB Output is correct
27 Correct 494 ms 6236 KB Output is correct
28 Correct 4 ms 5980 KB Output is correct
29 Correct 15 ms 6124 KB Output is correct
30 Correct 5 ms 5980 KB Output is correct
31 Correct 9 ms 5980 KB Output is correct
32 Correct 7 ms 5980 KB Output is correct
33 Correct 28 ms 6236 KB Output is correct
34 Correct 28 ms 6256 KB Output is correct
35 Correct 27 ms 5404 KB Output is correct
36 Correct 5 ms 3672 KB Output is correct
37 Correct 50 ms 7004 KB Output is correct
38 Correct 44 ms 7256 KB Output is correct
39 Correct 44 ms 7260 KB Output is correct
40 Correct 51 ms 7336 KB Output is correct
41 Correct 44 ms 7260 KB Output is correct
42 Execution timed out 1048 ms 7256 KB Time limit exceeded
43 Halted 0 ms 0 KB -