Submission #510300

# Submission time Handle Problem Language Result Execution time Memory
510300 2022-01-15T00:10:08 Z thiago_bastos Jakarta Skyscrapers (APIO15_skyscraper) C++17
57 / 100
1000 ms 183376 KB
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
 
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned;
using i16 = short;
using u16 = unsigned short;
using ld = long double;
using ii = pair<int, int>;

template<class K,class V> using ht = gp_hash_table<
		K,
		V,
		hash<K>,
		equal_to<K>,
		direct_mask_range_hashing<>,
		linear_probe_fn<>,
		hash_standard_resize_policy<
			hash_exponential_size_policy<>,
			hash_load_check_resize_trigger<>,
			true
		>
>;
 
const int N = 3e4 + 100, INF = 1e9;
 
vector<int> P[N];
ht<int, int> jumps[N];
int sz[N];
set<ii> s;

void solve() {
	int n, m;
 
	cin >> n >> m;
 
	vector<int> cnt(n, INF);
	queue<ii> q;
 
	int x0 = -1, x1 = -1;
 
	for(int i = 0; i < m; ++i) {
		int b, p;
		cin >> b >> p;
		if(!i) x0 = b;
		else if(i == 1) x1 = b;	
		if(!s.count(ii(b%p,p))) {
			s.insert(ii(b%p,p));
			for(int x=b%p;x<n;x+=p)++sz[x];
		}
		P[b].push_back(p);
	}

	for(int i=0;i<n;++i) jumps[i].resize(sz[i]);

	while(!P[x0].empty()) {
		int k = P[x0].back();
		P[x0].pop_back();
		if(jumps[x0][k] == 0) {
			jumps[x0][k] = 1;
			q.emplace(x0, k);
		}
	}

	while(!q.empty()) {
		auto [x, p] = q.front();

		q.pop();
 
		int j = jumps[x][p];
	
		cnt[x] = min(cnt[x], j);
 
		if(x == x1) break;
 
		if(x >= p && jumps[x - p][p] == 0) {
			jumps[x - p][p] = 1 + j;
			q.emplace(x - p, p);
		}
 
		if(x + p < n && jumps[x + p][p] == 0) {
			jumps[x + p][p] = 1 + j;
			q.emplace(x + p, p);
		}
 
		while(!P[x].empty()) {
			int k = P[x].back();
 
			P[x].pop_back();
 
			if(x >= k && jumps[x - k][k] == 0) {
				jumps[x - k][k] = 1 + j;
				q.emplace(x - k, k);
			}
 
			if(x + k < n && jumps[x + k][k] == 0) {
				jumps[x + k][k] = 1 + j;
				q.emplace(x + k, k);
			}
		}
	}

	if(cnt[x1] == INF) cout << "-1\n";
	else cout << cnt[x1] - 1 << '\n';
}
 
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 7360 KB Output is correct
2 Correct 6 ms 7372 KB Output is correct
3 Correct 6 ms 7372 KB Output is correct
4 Correct 7 ms 7320 KB Output is correct
5 Correct 6 ms 7372 KB Output is correct
6 Correct 8 ms 7372 KB Output is correct
7 Correct 6 ms 7372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7372 KB Output is correct
2 Correct 6 ms 7372 KB Output is correct
3 Correct 6 ms 7372 KB Output is correct
4 Correct 9 ms 7372 KB Output is correct
5 Correct 5 ms 7372 KB Output is correct
6 Correct 5 ms 7324 KB Output is correct
7 Correct 6 ms 7380 KB Output is correct
8 Correct 7 ms 7372 KB Output is correct
9 Correct 6 ms 7376 KB Output is correct
10 Correct 7 ms 7336 KB Output is correct
11 Correct 9 ms 7500 KB Output is correct
12 Correct 10 ms 7372 KB Output is correct
13 Correct 6 ms 7372 KB Output is correct
14 Correct 13 ms 7628 KB Output is correct
15 Correct 9 ms 7480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7372 KB Output is correct
2 Correct 9 ms 7392 KB Output is correct
3 Correct 6 ms 7260 KB Output is correct
4 Correct 9 ms 7372 KB Output is correct
5 Correct 8 ms 7328 KB Output is correct
6 Correct 10 ms 7376 KB Output is correct
7 Correct 6 ms 7372 KB Output is correct
8 Correct 6 ms 7372 KB Output is correct
9 Correct 8 ms 7392 KB Output is correct
10 Correct 11 ms 7372 KB Output is correct
11 Correct 8 ms 7500 KB Output is correct
12 Correct 9 ms 7320 KB Output is correct
13 Correct 11 ms 7400 KB Output is correct
14 Correct 8 ms 7628 KB Output is correct
15 Correct 7 ms 7500 KB Output is correct
16 Correct 7 ms 7504 KB Output is correct
17 Correct 8 ms 7616 KB Output is correct
18 Correct 11 ms 7372 KB Output is correct
19 Correct 10 ms 7392 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 11 ms 7444 KB Output is correct
22 Correct 9 ms 7376 KB Output is correct
23 Correct 11 ms 7500 KB Output is correct
24 Correct 9 ms 7612 KB Output is correct
25 Correct 10 ms 7500 KB Output is correct
26 Correct 6 ms 7372 KB Output is correct
27 Correct 7 ms 7372 KB Output is correct
28 Correct 9 ms 8012 KB Output is correct
29 Correct 16 ms 9672 KB Output is correct
30 Correct 14 ms 7884 KB Output is correct
31 Correct 12 ms 8760 KB Output is correct
32 Correct 11 ms 8048 KB Output is correct
33 Correct 20 ms 10940 KB Output is correct
34 Correct 13 ms 9672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7372 KB Output is correct
2 Correct 6 ms 7372 KB Output is correct
3 Correct 6 ms 7372 KB Output is correct
4 Correct 6 ms 7372 KB Output is correct
5 Correct 6 ms 7372 KB Output is correct
6 Correct 5 ms 7372 KB Output is correct
7 Correct 5 ms 7372 KB Output is correct
8 Correct 6 ms 7372 KB Output is correct
9 Correct 9 ms 7372 KB Output is correct
10 Correct 6 ms 7372 KB Output is correct
11 Correct 8 ms 7500 KB Output is correct
12 Correct 7 ms 7372 KB Output is correct
13 Correct 6 ms 7372 KB Output is correct
14 Correct 10 ms 7628 KB Output is correct
15 Correct 7 ms 7500 KB Output is correct
16 Correct 6 ms 7500 KB Output is correct
17 Correct 8 ms 7628 KB Output is correct
18 Correct 6 ms 7432 KB Output is correct
19 Correct 7 ms 7372 KB Output is correct
20 Correct 8 ms 7404 KB Output is correct
21 Correct 7 ms 7444 KB Output is correct
22 Correct 7 ms 7372 KB Output is correct
23 Correct 11 ms 7500 KB Output is correct
24 Correct 10 ms 7628 KB Output is correct
25 Correct 10 ms 7524 KB Output is correct
26 Correct 6 ms 7344 KB Output is correct
27 Correct 6 ms 7372 KB Output is correct
28 Correct 9 ms 8068 KB Output is correct
29 Correct 12 ms 9548 KB Output is correct
30 Correct 8 ms 7932 KB Output is correct
31 Correct 16 ms 8712 KB Output is correct
32 Correct 9 ms 8012 KB Output is correct
33 Correct 17 ms 10940 KB Output is correct
34 Correct 21 ms 9668 KB Output is correct
35 Correct 28 ms 10748 KB Output is correct
36 Correct 11 ms 7916 KB Output is correct
37 Correct 23 ms 11312 KB Output is correct
38 Correct 26 ms 11836 KB Output is correct
39 Correct 25 ms 11724 KB Output is correct
40 Correct 26 ms 11780 KB Output is correct
41 Correct 36 ms 11980 KB Output is correct
42 Correct 10 ms 7628 KB Output is correct
43 Correct 13 ms 7628 KB Output is correct
44 Correct 12 ms 7628 KB Output is correct
45 Correct 66 ms 21840 KB Output is correct
46 Correct 57 ms 18692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7344 KB Output is correct
2 Correct 6 ms 7372 KB Output is correct
3 Correct 6 ms 7372 KB Output is correct
4 Correct 6 ms 7372 KB Output is correct
5 Correct 6 ms 7372 KB Output is correct
6 Correct 7 ms 7372 KB Output is correct
7 Correct 10 ms 7376 KB Output is correct
8 Correct 6 ms 7372 KB Output is correct
9 Correct 6 ms 7372 KB Output is correct
10 Correct 6 ms 7372 KB Output is correct
11 Correct 7 ms 7500 KB Output is correct
12 Correct 6 ms 7372 KB Output is correct
13 Correct 6 ms 7408 KB Output is correct
14 Correct 11 ms 7616 KB Output is correct
15 Correct 10 ms 7500 KB Output is correct
16 Correct 10 ms 7372 KB Output is correct
17 Correct 8 ms 7628 KB Output is correct
18 Correct 8 ms 7372 KB Output is correct
19 Correct 9 ms 7608 KB Output is correct
20 Correct 10 ms 7372 KB Output is correct
21 Correct 6 ms 7372 KB Output is correct
22 Correct 6 ms 7444 KB Output is correct
23 Correct 10 ms 7448 KB Output is correct
24 Correct 8 ms 7664 KB Output is correct
25 Correct 7 ms 7468 KB Output is correct
26 Correct 6 ms 7372 KB Output is correct
27 Correct 7 ms 7372 KB Output is correct
28 Correct 15 ms 8040 KB Output is correct
29 Correct 13 ms 9652 KB Output is correct
30 Correct 11 ms 7884 KB Output is correct
31 Correct 11 ms 8760 KB Output is correct
32 Correct 11 ms 7988 KB Output is correct
33 Correct 15 ms 10916 KB Output is correct
34 Correct 13 ms 9756 KB Output is correct
35 Correct 41 ms 10720 KB Output is correct
36 Correct 14 ms 7884 KB Output is correct
37 Correct 24 ms 11328 KB Output is correct
38 Correct 47 ms 11896 KB Output is correct
39 Correct 46 ms 11716 KB Output is correct
40 Correct 48 ms 11828 KB Output is correct
41 Correct 44 ms 11960 KB Output is correct
42 Correct 11 ms 7628 KB Output is correct
43 Correct 17 ms 7672 KB Output is correct
44 Correct 12 ms 7628 KB Output is correct
45 Correct 61 ms 21836 KB Output is correct
46 Correct 47 ms 18592 KB Output is correct
47 Correct 46 ms 19388 KB Output is correct
48 Correct 25 ms 11068 KB Output is correct
49 Correct 28 ms 9572 KB Output is correct
50 Correct 22 ms 8932 KB Output is correct
51 Correct 41 ms 12500 KB Output is correct
52 Correct 42 ms 12732 KB Output is correct
53 Correct 31 ms 9656 KB Output is correct
54 Correct 11 ms 7500 KB Output is correct
55 Correct 8 ms 7612 KB Output is correct
56 Correct 14 ms 8552 KB Output is correct
57 Correct 15 ms 10428 KB Output is correct
58 Correct 20 ms 8776 KB Output is correct
59 Correct 26 ms 8356 KB Output is correct
60 Correct 26 ms 8332 KB Output is correct
61 Correct 18 ms 8516 KB Output is correct
62 Correct 151 ms 24356 KB Output is correct
63 Correct 648 ms 101236 KB Output is correct
64 Correct 754 ms 102748 KB Output is correct
65 Execution timed out 1053 ms 183376 KB Time limit exceeded
66 Halted 0 ms 0 KB -