Submission #954892

# Submission time Handle Problem Language Result Execution time Memory
954892 2024-03-28T19:03:35 Z colossal_pepe Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
1000 ms 3932 KB
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

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

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;
}
# Verdict Execution time Memory 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 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 456 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 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 668 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 452 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 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 456 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 776 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 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 4 ms 1988 KB Output is correct
20 Correct 297 ms 2300 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 2 ms 1628 KB Output is correct
24 Correct 4 ms 2140 KB Output is correct
25 Correct 2 ms 2140 KB Output is correct
26 Correct 469 ms 2264 KB Output is correct
27 Correct 499 ms 2396 KB Output is correct
28 Correct 3 ms 2136 KB Output is correct
29 Correct 13 ms 2220 KB Output is correct
30 Correct 4 ms 1992 KB Output is correct
31 Correct 8 ms 2140 KB Output is correct
32 Correct 5 ms 2140 KB Output is correct
33 Correct 27 ms 2140 KB Output is correct
34 Correct 27 ms 2140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 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 1 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 2 ms 604 KB Output is correct
12 Correct 28 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
16 Correct 1 ms 604 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 2140 KB Output is correct
20 Correct 299 ms 2540 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 1880 KB Output is correct
23 Correct 2 ms 1880 KB Output is correct
24 Correct 3 ms 2112 KB Output is correct
25 Correct 2 ms 2180 KB Output is correct
26 Correct 467 ms 2260 KB Output is correct
27 Correct 495 ms 2396 KB Output is correct
28 Correct 2 ms 2136 KB Output is correct
29 Correct 13 ms 2336 KB Output is correct
30 Correct 4 ms 2140 KB Output is correct
31 Correct 7 ms 2140 KB Output is correct
32 Correct 5 ms 2140 KB Output is correct
33 Correct 26 ms 2140 KB Output is correct
34 Correct 26 ms 2356 KB Output is correct
35 Correct 23 ms 2816 KB Output is correct
36 Correct 4 ms 1368 KB Output is correct
37 Correct 43 ms 3416 KB Output is correct
38 Correct 36 ms 3672 KB Output is correct
39 Correct 38 ms 3676 KB Output is correct
40 Correct 37 ms 3724 KB Output is correct
41 Correct 37 ms 3676 KB Output is correct
42 Execution timed out 1039 ms 3540 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 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 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 29 ms 860 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 1 ms 1884 KB Output is correct
19 Correct 1 ms 2140 KB Output is correct
20 Correct 299 ms 2316 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 1884 KB Output is correct
23 Correct 2 ms 1628 KB Output is correct
24 Correct 3 ms 2140 KB Output is correct
25 Correct 2 ms 2140 KB Output is correct
26 Correct 466 ms 2280 KB Output is correct
27 Correct 489 ms 2396 KB Output is correct
28 Correct 2 ms 2140 KB Output is correct
29 Correct 13 ms 2140 KB Output is correct
30 Correct 4 ms 1972 KB Output is correct
31 Correct 7 ms 2140 KB Output is correct
32 Correct 5 ms 2180 KB Output is correct
33 Correct 26 ms 2140 KB Output is correct
34 Correct 26 ms 2136 KB Output is correct
35 Correct 23 ms 2844 KB Output is correct
36 Correct 4 ms 1372 KB Output is correct
37 Correct 42 ms 3376 KB Output is correct
38 Correct 37 ms 3672 KB Output is correct
39 Correct 39 ms 3932 KB Output is correct
40 Correct 37 ms 3668 KB Output is correct
41 Correct 37 ms 3672 KB Output is correct
42 Execution timed out 1029 ms 3536 KB Time limit exceeded
43 Halted 0 ms 0 KB -