Submission #517032

# Submission time Handle Problem Language Result Execution time Memory
517032 2022-01-22T11:58:52 Z Drew_ Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
104 ms 63848 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

constexpr ld PI = 4*atan((ld)1);
constexpr int MAX = 30069;
constexpr int SQ = 250;	
constexpr int inf = 1e9 + 69;

int n, m;
int cost[MAX][SQ];

int b[MAX], p[MAX];
vector<int> adj[MAX];	

int main()
{
	fastio;

	for (int i = 0; i < MAX; ++i)
		for (int j = 0; j < SQ; ++j)
			cost[i][j] = inf;

	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> b[i] >> p[i];
		adj[b[i]].pb(p[i]);
	}

	const auto valid = [&](int pos) -> bool
	{
		return 0 <= pos && pos < n;
	};

	priority_queue<array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>>> pq;
	
	cost[b[0]][0] = 0;
	if (p[0] < SQ)
		cost[b[0]][p[0]] = 0;

	pq.push({0, b[0], p[0]});

	while (!pq.empty())
	{
		auto [c, pos, mov] = pq.top();
		pq.pop();

		if (cost[pos][mov] < c)
			continue;

		if (mov < SQ)
		{		
			if (cost[pos][0] > cost[pos][mov])
				cost[pos][0] = cost[pos][mov];
			if (valid(pos - mov) && cost[pos - mov][mov] > 1 + c)
				cost[pos - mov][mov] = 1 + c, pq.push({1 + c, pos - mov, mov});
			if (valid(pos + mov) && cost[pos + mov][mov] > 1 + c)
				cost[pos + mov][mov] = 1 + c, pq.push({1 + c, pos + mov, mov});
		}


		for (int x : adj[pos])
		{
			if (x < SQ)
			{
				if (valid(pos - x) && cost[pos - x][x] > 1 + c)
					cost[pos - x][x] = 1 + c, pq.push({1 + c, pos - x, x});
				if (valid(pos + x) && cost[pos + x] > 1 + cost[pos])
					cost[pos + x][x] = 1 + c, pq.push({1 + c, pos + x, x});
			}
			else
			{
				for (int i = pos, ctr = c; i >= 0; i -= x, ++ctr)
				{
					if (cost[i][0] > ctr)
						cost[i][0] = ctr, pq.push({ctr, i, x});
				}
				for (int i = pos, ctr = c; i < n; i += x, ++ctr)
				{
					if (cost[i][0] > ctr)
						cost[i][0] = ctr, pq.push({ctr, i, x});
				}
			}
		}
		adj[pos].clear();
	}

	// for (int i = 0; i < n; ++i)
	// 	cerr << cost[i] << " \n"[i == n-1];

	cout << (cost[b[1]][0] == inf ? -1 : cost[b[1]][0]) << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30412 KB Output is correct
2 Correct 15 ms 30376 KB Output is correct
3 Correct 15 ms 30352 KB Output is correct
4 Correct 15 ms 30412 KB Output is correct
5 Correct 14 ms 30356 KB Output is correct
6 Correct 14 ms 30384 KB Output is correct
7 Correct 14 ms 30380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30412 KB Output is correct
2 Correct 15 ms 30432 KB Output is correct
3 Correct 15 ms 30412 KB Output is correct
4 Correct 15 ms 30412 KB Output is correct
5 Correct 15 ms 30412 KB Output is correct
6 Correct 15 ms 30360 KB Output is correct
7 Correct 14 ms 30412 KB Output is correct
8 Correct 14 ms 30444 KB Output is correct
9 Correct 15 ms 30412 KB Output is correct
10 Correct 16 ms 30392 KB Output is correct
11 Correct 16 ms 30484 KB Output is correct
12 Correct 15 ms 30412 KB Output is correct
13 Correct 16 ms 30512 KB Output is correct
14 Correct 16 ms 30540 KB Output is correct
15 Correct 16 ms 30520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30372 KB Output is correct
2 Correct 15 ms 30428 KB Output is correct
3 Correct 14 ms 30444 KB Output is correct
4 Correct 15 ms 30432 KB Output is correct
5 Correct 16 ms 30412 KB Output is correct
6 Correct 15 ms 30324 KB Output is correct
7 Correct 14 ms 30332 KB Output is correct
8 Correct 16 ms 30376 KB Output is correct
9 Correct 17 ms 30412 KB Output is correct
10 Correct 15 ms 30412 KB Output is correct
11 Correct 17 ms 30492 KB Output is correct
12 Correct 17 ms 30412 KB Output is correct
13 Correct 16 ms 30444 KB Output is correct
14 Correct 16 ms 30540 KB Output is correct
15 Correct 16 ms 30448 KB Output is correct
16 Correct 16 ms 30464 KB Output is correct
17 Correct 17 ms 30412 KB Output is correct
18 Correct 15 ms 30456 KB Output is correct
19 Correct 16 ms 30412 KB Output is correct
20 Correct 17 ms 30492 KB Output is correct
21 Correct 15 ms 30412 KB Output is correct
22 Correct 15 ms 30412 KB Output is correct
23 Correct 16 ms 30412 KB Output is correct
24 Correct 17 ms 30412 KB Output is correct
25 Correct 15 ms 30412 KB Output is correct
26 Correct 15 ms 30412 KB Output is correct
27 Correct 15 ms 30412 KB Output is correct
28 Correct 17 ms 30412 KB Output is correct
29 Correct 22 ms 30412 KB Output is correct
30 Correct 16 ms 30420 KB Output is correct
31 Correct 18 ms 30412 KB Output is correct
32 Correct 16 ms 30420 KB Output is correct
33 Correct 28 ms 30540 KB Output is correct
34 Correct 28 ms 30576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30328 KB Output is correct
2 Correct 15 ms 30416 KB Output is correct
3 Correct 16 ms 30424 KB Output is correct
4 Correct 14 ms 30412 KB Output is correct
5 Correct 17 ms 30428 KB Output is correct
6 Correct 16 ms 30424 KB Output is correct
7 Correct 14 ms 30412 KB Output is correct
8 Correct 15 ms 30408 KB Output is correct
9 Correct 15 ms 30444 KB Output is correct
10 Correct 15 ms 30412 KB Output is correct
11 Correct 15 ms 30460 KB Output is correct
12 Correct 14 ms 30464 KB Output is correct
13 Correct 15 ms 30412 KB Output is correct
14 Correct 16 ms 30552 KB Output is correct
15 Correct 16 ms 30460 KB Output is correct
16 Correct 14 ms 30400 KB Output is correct
17 Correct 16 ms 30412 KB Output is correct
18 Correct 15 ms 30444 KB Output is correct
19 Correct 15 ms 30364 KB Output is correct
20 Correct 15 ms 30484 KB Output is correct
21 Correct 14 ms 30416 KB Output is correct
22 Correct 15 ms 30372 KB Output is correct
23 Correct 15 ms 30412 KB Output is correct
24 Correct 16 ms 30412 KB Output is correct
25 Correct 15 ms 30496 KB Output is correct
26 Correct 16 ms 30456 KB Output is correct
27 Correct 16 ms 30412 KB Output is correct
28 Correct 17 ms 30524 KB Output is correct
29 Correct 22 ms 30416 KB Output is correct
30 Correct 16 ms 30412 KB Output is correct
31 Correct 18 ms 30464 KB Output is correct
32 Correct 18 ms 30412 KB Output is correct
33 Correct 33 ms 30516 KB Output is correct
34 Correct 28 ms 30540 KB Output is correct
35 Correct 28 ms 31168 KB Output is correct
36 Correct 18 ms 30540 KB Output is correct
37 Correct 36 ms 31080 KB Output is correct
38 Correct 34 ms 31120 KB Output is correct
39 Correct 34 ms 31180 KB Output is correct
40 Correct 34 ms 31164 KB Output is correct
41 Correct 33 ms 31236 KB Output is correct
42 Correct 22 ms 31368 KB Output is correct
43 Correct 21 ms 31372 KB Output is correct
44 Correct 21 ms 31420 KB Output is correct
45 Correct 92 ms 31768 KB Output is correct
46 Correct 94 ms 31688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 30412 KB Output is correct
2 Correct 14 ms 30336 KB Output is correct
3 Correct 15 ms 30364 KB Output is correct
4 Correct 15 ms 30356 KB Output is correct
5 Correct 14 ms 30324 KB Output is correct
6 Correct 15 ms 30380 KB Output is correct
7 Correct 15 ms 30412 KB Output is correct
8 Correct 14 ms 30428 KB Output is correct
9 Correct 18 ms 30412 KB Output is correct
10 Correct 15 ms 30404 KB Output is correct
11 Correct 15 ms 30448 KB Output is correct
12 Correct 15 ms 30412 KB Output is correct
13 Correct 14 ms 30444 KB Output is correct
14 Correct 16 ms 30512 KB Output is correct
15 Correct 16 ms 30540 KB Output is correct
16 Correct 15 ms 30408 KB Output is correct
17 Correct 16 ms 30412 KB Output is correct
18 Correct 14 ms 30412 KB Output is correct
19 Correct 15 ms 30468 KB Output is correct
20 Correct 15 ms 30488 KB Output is correct
21 Correct 18 ms 30468 KB Output is correct
22 Correct 15 ms 30428 KB Output is correct
23 Correct 16 ms 30460 KB Output is correct
24 Correct 19 ms 30412 KB Output is correct
25 Correct 15 ms 30412 KB Output is correct
26 Correct 15 ms 30412 KB Output is correct
27 Correct 16 ms 30448 KB Output is correct
28 Correct 16 ms 30444 KB Output is correct
29 Correct 21 ms 30508 KB Output is correct
30 Correct 16 ms 30424 KB Output is correct
31 Correct 18 ms 30456 KB Output is correct
32 Correct 17 ms 30412 KB Output is correct
33 Correct 28 ms 30508 KB Output is correct
34 Correct 28 ms 30464 KB Output is correct
35 Correct 27 ms 31052 KB Output is correct
36 Correct 16 ms 30540 KB Output is correct
37 Correct 36 ms 31072 KB Output is correct
38 Correct 33 ms 31180 KB Output is correct
39 Correct 33 ms 31116 KB Output is correct
40 Correct 33 ms 31180 KB Output is correct
41 Correct 34 ms 31196 KB Output is correct
42 Correct 22 ms 31360 KB Output is correct
43 Correct 21 ms 31368 KB Output is correct
44 Correct 21 ms 31416 KB Output is correct
45 Correct 91 ms 31732 KB Output is correct
46 Correct 97 ms 31744 KB Output is correct
47 Correct 104 ms 31364 KB Output is correct
48 Correct 20 ms 31052 KB Output is correct
49 Correct 19 ms 31052 KB Output is correct
50 Correct 18 ms 30916 KB Output is correct
51 Runtime error 51 ms 63848 KB Execution killed with signal 11
52 Halted 0 ms 0 KB -