// #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;
ans[0] = 0;
cin >> n >> q;
rep(i, 0, n) {
cin >> p;
pq.emplace(0, p);
}
int val, prime;
rep(i, 1, 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;
else
ans[i] = ans[i - rem] + 1;
break;
} else {
pq.pop();
pq.emplace(-(i - i % prime), prime);
}
}
}
while (q--) {
cin >> val;
if (ans[val] >= INF)
cout << "oo" << endl;
else
cout << ans[val] << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
231 ms |
39436 KB |
Output is correct |
2 |
Correct |
208 ms |
39360 KB |
Output is correct |
3 |
Correct |
221 ms |
39364 KB |
Output is correct |
4 |
Correct |
163 ms |
39380 KB |
Output is correct |
5 |
Correct |
229 ms |
39412 KB |
Output is correct |
6 |
Correct |
229 ms |
39492 KB |
Output is correct |
7 |
Correct |
223 ms |
39324 KB |
Output is correct |
8 |
Correct |
225 ms |
39328 KB |
Output is correct |
9 |
Correct |
266 ms |
39364 KB |
Output is correct |
10 |
Correct |
237 ms |
39436 KB |
Output is correct |
11 |
Correct |
233 ms |
39364 KB |
Output is correct |
12 |
Correct |
165 ms |
39380 KB |
Output is correct |
13 |
Correct |
244 ms |
39364 KB |
Output is correct |
14 |
Correct |
260 ms |
39436 KB |
Output is correct |
15 |
Correct |
200 ms |
39392 KB |
Output is correct |
16 |
Correct |
211 ms |
39484 KB |
Output is correct |
17 |
Correct |
220 ms |
39364 KB |
Output is correct |
18 |
Correct |
169 ms |
39448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
39620 KB |
Output is correct |
2 |
Correct |
128 ms |
40216 KB |
Output is correct |
3 |
Correct |
167 ms |
39996 KB |
Output is correct |
4 |
Correct |
158 ms |
39388 KB |
Output is correct |
5 |
Correct |
170 ms |
39880 KB |
Output is correct |
6 |
Correct |
137 ms |
39392 KB |
Output is correct |
7 |
Correct |
130 ms |
39612 KB |
Output is correct |
8 |
Correct |
157 ms |
39412 KB |
Output is correct |
9 |
Correct |
200 ms |
40128 KB |
Output is correct |
10 |
Correct |
173 ms |
40132 KB |
Output is correct |
11 |
Correct |
210 ms |
39820 KB |
Output is correct |
12 |
Correct |
166 ms |
39480 KB |
Output is correct |
13 |
Correct |
129 ms |
39480 KB |
Output is correct |
14 |
Correct |
157 ms |
39408 KB |
Output is correct |
15 |
Correct |
192 ms |
39788 KB |
Output is correct |
16 |
Correct |
125 ms |
40204 KB |
Output is correct |
17 |
Correct |
197 ms |
39464 KB |
Output is correct |
18 |
Correct |
145 ms |
40272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
249 ms |
40036 KB |
Output is correct |
2 |
Correct |
264 ms |
40020 KB |
Output is correct |
3 |
Correct |
273 ms |
40096 KB |
Output is correct |
4 |
Correct |
277 ms |
39716 KB |
Output is correct |
5 |
Correct |
288 ms |
40512 KB |
Output is correct |
6 |
Correct |
313 ms |
39748 KB |
Output is correct |
7 |
Correct |
242 ms |
40484 KB |
Output is correct |
8 |
Correct |
237 ms |
39952 KB |
Output is correct |
9 |
Correct |
241 ms |
40004 KB |
Output is correct |
10 |
Correct |
206 ms |
39492 KB |
Output is correct |
11 |
Correct |
198 ms |
39528 KB |
Output is correct |
12 |
Correct |
223 ms |
39580 KB |
Output is correct |
13 |
Correct |
311 ms |
40152 KB |
Output is correct |
14 |
Correct |
402 ms |
40004 KB |
Output is correct |
15 |
Correct |
230 ms |
39540 KB |
Output is correct |
16 |
Correct |
250 ms |
39616 KB |
Output is correct |
17 |
Correct |
218 ms |
39836 KB |
Output is correct |
18 |
Correct |
257 ms |
40048 KB |
Output is correct |
19 |
Correct |
153 ms |
39620 KB |
Output is correct |
20 |
Correct |
275 ms |
40020 KB |
Output is correct |
21 |
Correct |
333 ms |
39980 KB |
Output is correct |
22 |
Correct |
349 ms |
40548 KB |
Output is correct |
23 |
Correct |
286 ms |
39928 KB |
Output is correct |
24 |
Correct |
262 ms |
39744 KB |
Output is correct |
25 |
Correct |
303 ms |
39816 KB |
Output is correct |
26 |
Correct |
267 ms |
39700 KB |
Output is correct |
27 |
Correct |
290 ms |
40436 KB |
Output is correct |
28 |
Correct |
247 ms |
39692 KB |
Output is correct |
29 |
Correct |
349 ms |
40500 KB |
Output is correct |
30 |
Correct |
353 ms |
40452 KB |
Output is correct |
31 |
Correct |
249 ms |
39832 KB |
Output is correct |
32 |
Correct |
276 ms |
39760 KB |
Output is correct |
33 |
Correct |
242 ms |
39624 KB |
Output is correct |
34 |
Correct |
244 ms |
40368 KB |
Output is correct |
35 |
Correct |
261 ms |
39668 KB |
Output is correct |
36 |
Correct |
331 ms |
40452 KB |
Output is correct |
37 |
Correct |
267 ms |
40516 KB |
Output is correct |
38 |
Correct |
307 ms |
39808 KB |
Output is correct |
39 |
Correct |
274 ms |
39900 KB |
Output is correct |
40 |
Correct |
288 ms |
39852 KB |
Output is correct |
41 |
Correct |
198 ms |
40360 KB |
Output is correct |
42 |
Correct |
342 ms |
39868 KB |
Output is correct |