// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout << #x << " = " << x << endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
int n, q, ans[10'000'001], rem;
priority_queue<ii> pq;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int p, mx;
ans[0] = 0;
cin >> n >> q;
rep(i, 0, n) {
cin >> p;
pq.emplace(0, p);
mx = p;
}
int val, prime, stop = INF;
rep(i, mx, 10'000'001) {
while (1) {
tie(val, prime) = pq.top();
val = -val;
if (i / prime == val / prime) {
rem = i - val;
if (!rem) {
ans[i] = INF;
stop = i;
} else if (i - rem < mx)
ans[i] = 2;
else
ans[i] = ans[i - rem] + 1;
break;
} else {
pq.pop();
pq.emplace(-(i - i % prime), prime);
}
}
if (stop != INF) break;
}
while (q--) {
cin >> val;
if (val<mx)
cout<<1<<endl;
else if (val>=stop)
cout << "oo" << endl;
else
cout << ans[val] << endl;
}
return 0;
}
Compilation message
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:61:24: warning: 'mx' may be used uninitialized in this function [-Wmaybe-uninitialized]
61 | } else if (i - rem < mx)
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
332 KB |
Output is correct |
2 |
Correct |
220 ms |
39424 KB |
Output is correct |
3 |
Correct |
6 ms |
1228 KB |
Output is correct |
4 |
Correct |
176 ms |
39388 KB |
Output is correct |
5 |
Correct |
230 ms |
39332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
6 ms |
1228 KB |
Output is correct |
8 |
Correct |
19 ms |
3840 KB |
Output is correct |
9 |
Correct |
265 ms |
39332 KB |
Output is correct |
10 |
Correct |
250 ms |
39432 KB |
Output is correct |
11 |
Correct |
250 ms |
39528 KB |
Output is correct |
12 |
Correct |
163 ms |
39500 KB |
Output is correct |
13 |
Correct |
239 ms |
39320 KB |
Output is correct |
14 |
Correct |
263 ms |
39364 KB |
Output is correct |
15 |
Correct |
191 ms |
39428 KB |
Output is correct |
16 |
Correct |
210 ms |
39496 KB |
Output is correct |
17 |
Correct |
218 ms |
39440 KB |
Output is correct |
18 |
Correct |
168 ms |
39428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
36044 KB |
Output is correct |
2 |
Correct |
36 ms |
4968 KB |
Output is correct |
3 |
Correct |
155 ms |
30292 KB |
Output is correct |
4 |
Correct |
156 ms |
39060 KB |
Output is correct |
5 |
Correct |
179 ms |
34880 KB |
Output is correct |
6 |
Correct |
141 ms |
39136 KB |
Output is correct |
7 |
Correct |
129 ms |
36036 KB |
Output is correct |
8 |
Correct |
165 ms |
39216 KB |
Output is correct |
9 |
Correct |
207 ms |
34992 KB |
Output is correct |
10 |
Correct |
150 ms |
30440 KB |
Output is correct |
11 |
Correct |
221 ms |
36348 KB |
Output is correct |
12 |
Correct |
172 ms |
39208 KB |
Output is correct |
13 |
Correct |
126 ms |
37468 KB |
Output is correct |
14 |
Correct |
173 ms |
39084 KB |
Output is correct |
15 |
Correct |
192 ms |
36696 KB |
Output is correct |
16 |
Correct |
29 ms |
5052 KB |
Output is correct |
17 |
Correct |
202 ms |
39148 KB |
Output is correct |
18 |
Correct |
106 ms |
20944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
237 ms |
36136 KB |
Output is correct |
2 |
Correct |
284 ms |
37300 KB |
Output is correct |
3 |
Correct |
281 ms |
36376 KB |
Output is correct |
4 |
Correct |
292 ms |
39324 KB |
Output is correct |
5 |
Correct |
222 ms |
23204 KB |
Output is correct |
6 |
Correct |
326 ms |
39316 KB |
Output is correct |
7 |
Correct |
231 ms |
29336 KB |
Output is correct |
8 |
Correct |
239 ms |
36244 KB |
Output is correct |
9 |
Correct |
242 ms |
36088 KB |
Output is correct |
10 |
Correct |
208 ms |
39236 KB |
Output is correct |
11 |
Correct |
204 ms |
39244 KB |
Output is correct |
12 |
Correct |
232 ms |
39116 KB |
Output is correct |
13 |
Correct |
301 ms |
36916 KB |
Output is correct |
14 |
Correct |
411 ms |
40036 KB |
Output is correct |
15 |
Correct |
243 ms |
39236 KB |
Output is correct |
16 |
Correct |
267 ms |
39392 KB |
Output is correct |
17 |
Correct |
208 ms |
36744 KB |
Output is correct |
18 |
Correct |
255 ms |
37224 KB |
Output is correct |
19 |
Correct |
150 ms |
36784 KB |
Output is correct |
20 |
Correct |
302 ms |
36280 KB |
Output is correct |
21 |
Correct |
344 ms |
40004 KB |
Output is correct |
22 |
Correct |
352 ms |
34604 KB |
Output is correct |
23 |
Correct |
289 ms |
36128 KB |
Output is correct |
24 |
Correct |
266 ms |
39428 KB |
Output is correct |
25 |
Correct |
317 ms |
39584 KB |
Output is correct |
26 |
Correct |
294 ms |
39244 KB |
Output is correct |
27 |
Correct |
308 ms |
33984 KB |
Output is correct |
28 |
Correct |
253 ms |
38936 KB |
Output is correct |
29 |
Correct |
337 ms |
34616 KB |
Output is correct |
30 |
Correct |
346 ms |
36384 KB |
Output is correct |
31 |
Correct |
248 ms |
38580 KB |
Output is correct |
32 |
Correct |
285 ms |
39348 KB |
Output is correct |
33 |
Correct |
243 ms |
38940 KB |
Output is correct |
34 |
Correct |
212 ms |
29228 KB |
Output is correct |
35 |
Correct |
266 ms |
38968 KB |
Output is correct |
36 |
Correct |
335 ms |
34500 KB |
Output is correct |
37 |
Correct |
217 ms |
23100 KB |
Output is correct |
38 |
Correct |
344 ms |
39316 KB |
Output is correct |
39 |
Correct |
281 ms |
39184 KB |
Output is correct |
40 |
Correct |
308 ms |
39052 KB |
Output is correct |
41 |
Correct |
149 ms |
11652 KB |
Output is correct |
42 |
Correct |
342 ms |
39680 KB |
Output is correct |