// #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" << '\n';
else
cout << ans[val] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
39416 KB |
Output is correct |
2 |
Correct |
205 ms |
39312 KB |
Output is correct |
3 |
Correct |
221 ms |
39364 KB |
Output is correct |
4 |
Correct |
154 ms |
39448 KB |
Output is correct |
5 |
Correct |
231 ms |
39320 KB |
Output is correct |
6 |
Correct |
240 ms |
39408 KB |
Output is correct |
7 |
Correct |
223 ms |
39376 KB |
Output is correct |
8 |
Correct |
222 ms |
39364 KB |
Output is correct |
9 |
Correct |
262 ms |
39460 KB |
Output is correct |
10 |
Correct |
228 ms |
39524 KB |
Output is correct |
11 |
Correct |
227 ms |
39424 KB |
Output is correct |
12 |
Correct |
164 ms |
39324 KB |
Output is correct |
13 |
Correct |
246 ms |
39452 KB |
Output is correct |
14 |
Correct |
240 ms |
39412 KB |
Output is correct |
15 |
Correct |
189 ms |
39352 KB |
Output is correct |
16 |
Correct |
203 ms |
39332 KB |
Output is correct |
17 |
Correct |
208 ms |
39420 KB |
Output is correct |
18 |
Correct |
154 ms |
39432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
39620 KB |
Output is correct |
2 |
Correct |
128 ms |
40320 KB |
Output is correct |
3 |
Correct |
171 ms |
40128 KB |
Output is correct |
4 |
Correct |
155 ms |
39384 KB |
Output is correct |
5 |
Correct |
172 ms |
39976 KB |
Output is correct |
6 |
Correct |
146 ms |
39492 KB |
Output is correct |
7 |
Correct |
132 ms |
39648 KB |
Output is correct |
8 |
Correct |
156 ms |
39416 KB |
Output is correct |
9 |
Correct |
197 ms |
40136 KB |
Output is correct |
10 |
Correct |
172 ms |
40116 KB |
Output is correct |
11 |
Correct |
205 ms |
39780 KB |
Output is correct |
12 |
Correct |
169 ms |
39428 KB |
Output is correct |
13 |
Correct |
122 ms |
39492 KB |
Output is correct |
14 |
Correct |
155 ms |
39492 KB |
Output is correct |
15 |
Correct |
203 ms |
39808 KB |
Output is correct |
16 |
Correct |
126 ms |
40340 KB |
Output is correct |
17 |
Correct |
196 ms |
39472 KB |
Output is correct |
18 |
Correct |
148 ms |
40352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
40004 KB |
Output is correct |
2 |
Correct |
232 ms |
39928 KB |
Output is correct |
3 |
Correct |
235 ms |
40132 KB |
Output is correct |
4 |
Correct |
183 ms |
39636 KB |
Output is correct |
5 |
Correct |
160 ms |
40544 KB |
Output is correct |
6 |
Correct |
228 ms |
39920 KB |
Output is correct |
7 |
Correct |
177 ms |
40424 KB |
Output is correct |
8 |
Correct |
201 ms |
40028 KB |
Output is correct |
9 |
Correct |
205 ms |
39996 KB |
Output is correct |
10 |
Correct |
196 ms |
39572 KB |
Output is correct |
11 |
Correct |
175 ms |
39572 KB |
Output is correct |
12 |
Correct |
192 ms |
39532 KB |
Output is correct |
13 |
Correct |
212 ms |
40068 KB |
Output is correct |
14 |
Correct |
294 ms |
39940 KB |
Output is correct |
15 |
Correct |
203 ms |
39616 KB |
Output is correct |
16 |
Correct |
236 ms |
39544 KB |
Output is correct |
17 |
Correct |
222 ms |
39912 KB |
Output is correct |
18 |
Correct |
240 ms |
40004 KB |
Output is correct |
19 |
Correct |
131 ms |
39560 KB |
Output is correct |
20 |
Correct |
219 ms |
40128 KB |
Output is correct |
21 |
Correct |
221 ms |
39996 KB |
Output is correct |
22 |
Correct |
239 ms |
40556 KB |
Output is correct |
23 |
Correct |
179 ms |
39948 KB |
Output is correct |
24 |
Correct |
155 ms |
39716 KB |
Output is correct |
25 |
Correct |
212 ms |
39704 KB |
Output is correct |
26 |
Correct |
177 ms |
39684 KB |
Output is correct |
27 |
Correct |
235 ms |
40392 KB |
Output is correct |
28 |
Correct |
145 ms |
39740 KB |
Output is correct |
29 |
Correct |
238 ms |
40548 KB |
Output is correct |
30 |
Correct |
245 ms |
40304 KB |
Output is correct |
31 |
Correct |
157 ms |
39664 KB |
Output is correct |
32 |
Correct |
186 ms |
39848 KB |
Output is correct |
33 |
Correct |
147 ms |
39612 KB |
Output is correct |
34 |
Correct |
174 ms |
40476 KB |
Output is correct |
35 |
Correct |
157 ms |
39748 KB |
Output is correct |
36 |
Correct |
228 ms |
40452 KB |
Output is correct |
37 |
Correct |
157 ms |
40516 KB |
Output is correct |
38 |
Correct |
217 ms |
39708 KB |
Output is correct |
39 |
Correct |
164 ms |
39748 KB |
Output is correct |
40 |
Correct |
201 ms |
39828 KB |
Output is correct |
41 |
Correct |
143 ms |
40464 KB |
Output is correct |
42 |
Correct |
229 ms |
39876 KB |
Output is correct |