Submission #719878

# Submission time Handle Problem Language Result Execution time Memory
719878 2023-04-07T00:40:49 Z thiago_bastos Brunhilda’s Birthday (BOI13_brunhilda) C++17
100 / 100
273 ms 79688 KB
#include "bits/stdc++.h"

using namespace std;

//#define INF   1000000000
#define INFLL 1000000000000000000ll
#define EPS 1e-9
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define fi first
#define sc second

using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using ii = pair<int, int>;
using i128 = __int128;

const int N = 1e7 + 10, INF = 0x3f3f3f3f;

int steps[N], maxp[N], cur, pq[N];

void push(int a, int b) {
	pq[b] = max(pq[b], a);
}

int top(int r) {
	while(cur < N && pq[cur] <= r) ++cur;
	return cur < N ? cur : INF;
}

void solve() {
	int m, q;
	
	cin >> m >> q;

	memset(steps, 0x3f, sizeof steps);
	
	for(int i = 0; i < m; ++i) {
		int p;
		cin >> p;
		for(int j = 0; j < N; j += p) maxp[j] = p;
	}

	push(maxp[0], 1);

	for(int i = 1; i < N; ++i) {
		steps[i] = top(i);
		if(maxp[i] && steps[i] < INF) push(i + maxp[i], steps[i] + 1);	
	}

	while(q--) {
		int n;
		cin >> n;
		if(steps[n] == INF) {
			cout << "oo\n";
			continue;
		}
		cout << steps[n] << '\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 62 ms 78668 KB Output is correct
2 Correct 72 ms 78596 KB Output is correct
3 Correct 67 ms 78584 KB Output is correct
4 Correct 56 ms 78684 KB Output is correct
5 Correct 82 ms 79220 KB Output is correct
6 Correct 60 ms 78648 KB Output is correct
7 Correct 66 ms 78600 KB Output is correct
8 Correct 71 ms 78788 KB Output is correct
9 Correct 95 ms 79688 KB Output is correct
10 Correct 111 ms 78844 KB Output is correct
11 Correct 105 ms 78924 KB Output is correct
12 Correct 52 ms 78588 KB Output is correct
13 Correct 153 ms 78588 KB Output is correct
14 Correct 162 ms 78588 KB Output is correct
15 Correct 85 ms 78624 KB Output is correct
16 Correct 80 ms 78616 KB Output is correct
17 Correct 89 ms 78668 KB Output is correct
18 Correct 56 ms 78596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 78548 KB Output is correct
2 Correct 93 ms 78588 KB Output is correct
3 Correct 184 ms 78592 KB Output is correct
4 Correct 115 ms 78584 KB Output is correct
5 Correct 145 ms 78584 KB Output is correct
6 Correct 81 ms 78584 KB Output is correct
7 Correct 82 ms 78592 KB Output is correct
8 Correct 111 ms 78588 KB Output is correct
9 Correct 147 ms 78588 KB Output is correct
10 Correct 193 ms 78584 KB Output is correct
11 Correct 178 ms 78584 KB Output is correct
12 Correct 113 ms 78588 KB Output is correct
13 Correct 67 ms 78584 KB Output is correct
14 Correct 106 ms 78524 KB Output is correct
15 Correct 167 ms 78584 KB Output is correct
16 Correct 91 ms 78592 KB Output is correct
17 Correct 154 ms 78588 KB Output is correct
18 Correct 157 ms 78472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 78796 KB Output is correct
2 Correct 192 ms 78588 KB Output is correct
3 Correct 218 ms 78924 KB Output is correct
4 Correct 138 ms 78944 KB Output is correct
5 Correct 126 ms 78716 KB Output is correct
6 Correct 174 ms 78976 KB Output is correct
7 Correct 161 ms 78968 KB Output is correct
8 Correct 166 ms 78844 KB Output is correct
9 Correct 171 ms 78844 KB Output is correct
10 Correct 143 ms 78592 KB Output is correct
11 Correct 144 ms 78668 KB Output is correct
12 Correct 165 ms 78592 KB Output is correct
13 Correct 191 ms 79480 KB Output is correct
14 Correct 123 ms 79504 KB Output is correct
15 Correct 152 ms 78716 KB Output is correct
16 Correct 170 ms 78648 KB Output is correct
17 Correct 149 ms 78604 KB Output is correct
18 Correct 192 ms 78776 KB Output is correct
19 Correct 68 ms 78580 KB Output is correct
20 Correct 191 ms 78848 KB Output is correct
21 Correct 137 ms 79228 KB Output is correct
22 Correct 209 ms 79356 KB Output is correct
23 Correct 115 ms 78732 KB Output is correct
24 Correct 93 ms 78844 KB Output is correct
25 Correct 146 ms 78844 KB Output is correct
26 Correct 132 ms 78844 KB Output is correct
27 Correct 208 ms 78844 KB Output is correct
28 Correct 90 ms 78820 KB Output is correct
29 Correct 194 ms 79356 KB Output is correct
30 Correct 175 ms 79436 KB Output is correct
31 Correct 117 ms 78724 KB Output is correct
32 Correct 133 ms 78844 KB Output is correct
33 Correct 79 ms 78840 KB Output is correct
34 Correct 156 ms 78904 KB Output is correct
35 Correct 97 ms 78868 KB Output is correct
36 Correct 273 ms 79352 KB Output is correct
37 Correct 130 ms 78684 KB Output is correct
38 Correct 211 ms 78920 KB Output is correct
39 Correct 132 ms 78864 KB Output is correct
40 Correct 147 ms 78852 KB Output is correct
41 Correct 138 ms 78924 KB Output is correct
42 Correct 184 ms 79224 KB Output is correct