// #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);
}
}
assert(ans[i]>=ans[i-1]);
}
while (q--) {
cin >> val;
if (ans[val] == INF)
cout << "oo" << endl;
else
cout << ans[val] << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
2 |
Correct |
206 ms |
39424 KB |
Output is correct |
3 |
Runtime error |
14 ms |
4684 KB |
Execution killed with signal 6 |
4 |
Correct |
160 ms |
39364 KB |
Output is correct |
5 |
Correct |
239 ms |
39324 KB |
Output is correct |
6 |
Runtime error |
2 ms |
588 KB |
Execution killed with signal 6 |
7 |
Runtime error |
15 ms |
4700 KB |
Execution killed with signal 6 |
8 |
Runtime error |
45 ms |
14788 KB |
Execution killed with signal 6 |
9 |
Correct |
259 ms |
39368 KB |
Output is correct |
10 |
Correct |
234 ms |
39364 KB |
Output is correct |
11 |
Correct |
223 ms |
39360 KB |
Output is correct |
12 |
Correct |
162 ms |
39392 KB |
Output is correct |
13 |
Correct |
236 ms |
39492 KB |
Output is correct |
14 |
Correct |
253 ms |
39440 KB |
Output is correct |
15 |
Correct |
187 ms |
39364 KB |
Output is correct |
16 |
Correct |
212 ms |
39428 KB |
Output is correct |
17 |
Correct |
226 ms |
39492 KB |
Output is correct |
18 |
Correct |
162 ms |
39528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
39628 KB |
Output is correct |
2 |
Correct |
137 ms |
40256 KB |
Output is correct |
3 |
Correct |
169 ms |
40000 KB |
Output is correct |
4 |
Correct |
155 ms |
39368 KB |
Output is correct |
5 |
Correct |
168 ms |
39960 KB |
Output is correct |
6 |
Correct |
139 ms |
39364 KB |
Output is correct |
7 |
Correct |
140 ms |
39564 KB |
Output is correct |
8 |
Correct |
162 ms |
39364 KB |
Output is correct |
9 |
Correct |
199 ms |
40020 KB |
Output is correct |
10 |
Correct |
177 ms |
40104 KB |
Output is correct |
11 |
Correct |
200 ms |
39852 KB |
Output is correct |
12 |
Correct |
164 ms |
39436 KB |
Output is correct |
13 |
Correct |
124 ms |
39492 KB |
Output is correct |
14 |
Correct |
164 ms |
39448 KB |
Output is correct |
15 |
Correct |
188 ms |
39880 KB |
Output is correct |
16 |
Correct |
125 ms |
40232 KB |
Output is correct |
17 |
Correct |
206 ms |
39480 KB |
Output is correct |
18 |
Correct |
157 ms |
40356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
242 ms |
40016 KB |
Output is correct |
2 |
Correct |
266 ms |
39988 KB |
Output is correct |
3 |
Correct |
295 ms |
40140 KB |
Output is correct |
4 |
Correct |
278 ms |
39732 KB |
Output is correct |
5 |
Correct |
268 ms |
40644 KB |
Output is correct |
6 |
Correct |
316 ms |
39804 KB |
Output is correct |
7 |
Correct |
232 ms |
40412 KB |
Output is correct |
8 |
Correct |
255 ms |
40096 KB |
Output is correct |
9 |
Correct |
242 ms |
39952 KB |
Output is correct |
10 |
Correct |
217 ms |
39472 KB |
Output is correct |
11 |
Correct |
222 ms |
39512 KB |
Output is correct |
12 |
Correct |
218 ms |
39504 KB |
Output is correct |
13 |
Correct |
312 ms |
39972 KB |
Output is correct |
14 |
Correct |
399 ms |
39900 KB |
Output is correct |
15 |
Correct |
250 ms |
39612 KB |
Output is correct |
16 |
Correct |
272 ms |
39524 KB |
Output is correct |
17 |
Correct |
212 ms |
39844 KB |
Output is correct |
18 |
Correct |
274 ms |
39988 KB |
Output is correct |
19 |
Correct |
152 ms |
39492 KB |
Output is correct |
20 |
Correct |
284 ms |
40060 KB |
Output is correct |
21 |
Correct |
362 ms |
39916 KB |
Output is correct |
22 |
Correct |
346 ms |
40444 KB |
Output is correct |
23 |
Correct |
296 ms |
40088 KB |
Output is correct |
24 |
Correct |
256 ms |
39636 KB |
Output is correct |
25 |
Correct |
308 ms |
39728 KB |
Output is correct |
26 |
Correct |
275 ms |
39840 KB |
Output is correct |
27 |
Correct |
299 ms |
40428 KB |
Output is correct |
28 |
Correct |
252 ms |
39716 KB |
Output is correct |
29 |
Correct |
358 ms |
40608 KB |
Output is correct |
30 |
Correct |
359 ms |
40292 KB |
Output is correct |
31 |
Correct |
249 ms |
39664 KB |
Output is correct |
32 |
Correct |
284 ms |
39660 KB |
Output is correct |
33 |
Correct |
246 ms |
39692 KB |
Output is correct |
34 |
Correct |
232 ms |
40468 KB |
Output is correct |
35 |
Correct |
266 ms |
39760 KB |
Output is correct |
36 |
Correct |
356 ms |
40408 KB |
Output is correct |
37 |
Correct |
265 ms |
40536 KB |
Output is correct |
38 |
Correct |
369 ms |
39860 KB |
Output is correct |
39 |
Correct |
281 ms |
39748 KB |
Output is correct |
40 |
Correct |
325 ms |
39988 KB |
Output is correct |
41 |
Correct |
202 ms |
40392 KB |
Output is correct |
42 |
Correct |
361 ms |
39888 KB |
Output is correct |