Submission #488587

# Submission time Handle Problem Language Result Execution time Memory
488587 2021-11-19T17:47:57 Z pooyashams Jakarta Skyscrapers (APIO15_skyscraper) C++14
100 / 100
425 ms 169268 KB
#include <algorithm>
#include <iostream>
#include <cstring>
#include <numeric>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 3e4+10;
const int mxsq = 55;
const int maxt = maxn*mxsq;
const int inf = 1e9+7;

int len[maxn];
int pos[maxn];
int dist[maxt];
vector<pii> G[maxt];

inline void add_edge(int a, int b, int w, bool nd)
{
	G[a].push_back({w, b});
	if(nd)
		G[b].push_back({w, a});
}

priority_queue<pii, vector<pii>, greater<pii>> pq;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m; cin >> m >> n;
	const int sq = 50;
	for(int p = 1; p < sq; p++)
	{
		for(int i = 0; i < m; i++)
		{
			if(i + p < m)
				add_edge(p*m+i, p*m+i+p, 1, true);
			add_edge(p*m+i, i, 0, false);
		}
	}
	for(int i = 0; i < n; i++)
	{
		cin >> pos[i] >> len[i];
		int b = pos[i];
		int p = len[i];
		if(p >= sq)
		{
			for(int j = b%p; j < m; j += p)
			{
				add_edge(b, j, abs(b-j)/p, false);
			}
		}
		else
		{
			add_edge(b, p*m+b, 0, false);
		}
	}
	fill(dist, dist+maxt, inf);
	dist[pos[0]] = 0;
	pq.push({0, pos[0]});
	while(!pq.empty())
	{
		int t = pq.top().second; 
		int d = pq.top().first;
		pq.pop();
		for(pii e: G[t])
		{
			int u = e.second;
			int w = d+e.first;
			if(dist[u] <= w)
				continue;
			dist[u] = w;
			pq.push({dist[u], u});
		}
	}
	int x = dist[pos[1]];
	if(x == inf) x = -1;
	cout << x << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 45516 KB Output is correct
2 Correct 23 ms 45488 KB Output is correct
3 Correct 23 ms 45540 KB Output is correct
4 Correct 26 ms 45504 KB Output is correct
5 Correct 24 ms 45516 KB Output is correct
6 Correct 23 ms 45452 KB Output is correct
7 Correct 24 ms 45456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 45516 KB Output is correct
2 Correct 27 ms 45516 KB Output is correct
3 Correct 25 ms 45516 KB Output is correct
4 Correct 24 ms 45500 KB Output is correct
5 Correct 24 ms 45552 KB Output is correct
6 Correct 25 ms 45516 KB Output is correct
7 Correct 23 ms 45516 KB Output is correct
8 Correct 24 ms 45508 KB Output is correct
9 Correct 24 ms 45556 KB Output is correct
10 Correct 25 ms 45804 KB Output is correct
11 Correct 25 ms 45692 KB Output is correct
12 Correct 25 ms 45672 KB Output is correct
13 Correct 25 ms 45796 KB Output is correct
14 Correct 26 ms 45772 KB Output is correct
15 Correct 26 ms 45812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 45516 KB Output is correct
2 Correct 26 ms 45528 KB Output is correct
3 Correct 24 ms 45512 KB Output is correct
4 Correct 25 ms 45508 KB Output is correct
5 Correct 22 ms 45540 KB Output is correct
6 Correct 25 ms 45464 KB Output is correct
7 Correct 24 ms 45516 KB Output is correct
8 Correct 24 ms 45516 KB Output is correct
9 Correct 25 ms 45516 KB Output is correct
10 Correct 25 ms 45636 KB Output is correct
11 Correct 27 ms 45760 KB Output is correct
12 Correct 25 ms 45700 KB Output is correct
13 Correct 28 ms 45860 KB Output is correct
14 Correct 27 ms 45716 KB Output is correct
15 Correct 26 ms 45712 KB Output is correct
16 Correct 26 ms 45956 KB Output is correct
17 Correct 32 ms 47308 KB Output is correct
18 Correct 33 ms 49476 KB Output is correct
19 Correct 33 ms 50036 KB Output is correct
20 Correct 35 ms 50168 KB Output is correct
21 Correct 26 ms 46392 KB Output is correct
22 Correct 37 ms 49528 KB Output is correct
23 Correct 33 ms 49204 KB Output is correct
24 Correct 36 ms 49988 KB Output is correct
25 Correct 41 ms 50148 KB Output is correct
26 Correct 38 ms 50180 KB Output is correct
27 Correct 34 ms 50084 KB Output is correct
28 Correct 36 ms 50180 KB Output is correct
29 Correct 40 ms 50020 KB Output is correct
30 Correct 38 ms 50012 KB Output is correct
31 Correct 35 ms 50124 KB Output is correct
32 Correct 36 ms 50124 KB Output is correct
33 Correct 42 ms 50652 KB Output is correct
34 Correct 56 ms 50688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 45544 KB Output is correct
2 Correct 27 ms 45536 KB Output is correct
3 Correct 22 ms 45508 KB Output is correct
4 Correct 23 ms 45524 KB Output is correct
5 Correct 23 ms 45548 KB Output is correct
6 Correct 24 ms 45448 KB Output is correct
7 Correct 25 ms 45480 KB Output is correct
8 Correct 24 ms 45516 KB Output is correct
9 Correct 24 ms 45608 KB Output is correct
10 Correct 25 ms 45724 KB Output is correct
11 Correct 27 ms 45800 KB Output is correct
12 Correct 24 ms 45772 KB Output is correct
13 Correct 25 ms 45772 KB Output is correct
14 Correct 31 ms 45684 KB Output is correct
15 Correct 29 ms 45816 KB Output is correct
16 Correct 26 ms 45880 KB Output is correct
17 Correct 29 ms 47280 KB Output is correct
18 Correct 33 ms 49476 KB Output is correct
19 Correct 38 ms 50076 KB Output is correct
20 Correct 43 ms 50124 KB Output is correct
21 Correct 26 ms 46336 KB Output is correct
22 Correct 33 ms 49604 KB Output is correct
23 Correct 34 ms 49104 KB Output is correct
24 Correct 35 ms 49996 KB Output is correct
25 Correct 40 ms 50164 KB Output is correct
26 Correct 35 ms 50184 KB Output is correct
27 Correct 34 ms 50108 KB Output is correct
28 Correct 43 ms 50152 KB Output is correct
29 Correct 42 ms 50116 KB Output is correct
30 Correct 34 ms 49992 KB Output is correct
31 Correct 40 ms 50116 KB Output is correct
32 Correct 35 ms 50120 KB Output is correct
33 Correct 42 ms 50692 KB Output is correct
34 Correct 43 ms 50576 KB Output is correct
35 Correct 44 ms 49960 KB Output is correct
36 Correct 32 ms 48196 KB Output is correct
37 Correct 52 ms 51728 KB Output is correct
38 Correct 53 ms 51812 KB Output is correct
39 Correct 51 ms 51884 KB Output is correct
40 Correct 50 ms 51780 KB Output is correct
41 Correct 51 ms 51756 KB Output is correct
42 Correct 39 ms 50632 KB Output is correct
43 Correct 38 ms 50696 KB Output is correct
44 Correct 38 ms 50632 KB Output is correct
45 Correct 50 ms 54432 KB Output is correct
46 Correct 49 ms 54468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 45516 KB Output is correct
2 Correct 23 ms 45432 KB Output is correct
3 Correct 23 ms 45512 KB Output is correct
4 Correct 31 ms 45508 KB Output is correct
5 Correct 23 ms 45516 KB Output is correct
6 Correct 23 ms 45480 KB Output is correct
7 Correct 24 ms 45584 KB Output is correct
8 Correct 26 ms 45516 KB Output is correct
9 Correct 24 ms 45644 KB Output is correct
10 Correct 24 ms 45684 KB Output is correct
11 Correct 23 ms 45772 KB Output is correct
12 Correct 25 ms 45688 KB Output is correct
13 Correct 26 ms 45756 KB Output is correct
14 Correct 30 ms 45780 KB Output is correct
15 Correct 26 ms 45772 KB Output is correct
16 Correct 26 ms 45960 KB Output is correct
17 Correct 35 ms 47268 KB Output is correct
18 Correct 32 ms 49480 KB Output is correct
19 Correct 33 ms 50036 KB Output is correct
20 Correct 35 ms 50080 KB Output is correct
21 Correct 26 ms 46524 KB Output is correct
22 Correct 33 ms 49612 KB Output is correct
23 Correct 33 ms 49212 KB Output is correct
24 Correct 36 ms 49868 KB Output is correct
25 Correct 40 ms 50104 KB Output is correct
26 Correct 46 ms 50112 KB Output is correct
27 Correct 47 ms 50052 KB Output is correct
28 Correct 35 ms 50252 KB Output is correct
29 Correct 38 ms 50060 KB Output is correct
30 Correct 34 ms 49968 KB Output is correct
31 Correct 37 ms 50020 KB Output is correct
32 Correct 36 ms 50124 KB Output is correct
33 Correct 42 ms 50664 KB Output is correct
34 Correct 42 ms 50612 KB Output is correct
35 Correct 49 ms 49948 KB Output is correct
36 Correct 33 ms 48152 KB Output is correct
37 Correct 53 ms 51724 KB Output is correct
38 Correct 50 ms 51844 KB Output is correct
39 Correct 52 ms 51824 KB Output is correct
40 Correct 53 ms 51920 KB Output is correct
41 Correct 50 ms 51872 KB Output is correct
42 Correct 37 ms 50688 KB Output is correct
43 Correct 37 ms 50680 KB Output is correct
44 Correct 37 ms 50672 KB Output is correct
45 Correct 50 ms 54524 KB Output is correct
46 Correct 50 ms 54464 KB Output is correct
47 Correct 181 ms 80120 KB Output is correct
48 Correct 142 ms 100848 KB Output is correct
49 Correct 151 ms 105516 KB Output is correct
50 Correct 181 ms 110896 KB Output is correct
51 Correct 210 ms 117508 KB Output is correct
52 Correct 217 ms 117704 KB Output is correct
53 Correct 179 ms 115412 KB Output is correct
54 Correct 200 ms 114404 KB Output is correct
55 Correct 173 ms 114588 KB Output is correct
56 Correct 197 ms 115672 KB Output is correct
57 Correct 290 ms 115652 KB Output is correct
58 Correct 179 ms 115068 KB Output is correct
59 Correct 196 ms 115136 KB Output is correct
60 Correct 197 ms 115776 KB Output is correct
61 Correct 194 ms 115400 KB Output is correct
62 Correct 208 ms 118472 KB Output is correct
63 Correct 238 ms 139200 KB Output is correct
64 Correct 257 ms 148004 KB Output is correct
65 Correct 275 ms 153768 KB Output is correct
66 Correct 425 ms 168616 KB Output is correct
67 Correct 412 ms 169268 KB Output is correct