#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i, a, b) for (int i=a;i>=b;--i)
const int MX_M = 1e5+5;
const int MX_Q = 1e5+5;
const int MX_P = 2e7+10;
const int infty = 1e9;
int M, Q, P[MX_M];
int pi[MX_P], dp[MX_P];
using ii = pair<int, int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> M >> Q;
FOR(i,1,M){
cin >> P[i];
for (int j = P[i]; j < MX_P; j += P[i]) pi[j-1] = P[i]-1;
}
RFOR(i,MX_P-2,0) pi[i] = max(pi[i],pi[i+1]-1);
dp[0] = 0;
FOR(i,1,MX_P-1) {
assert(pi[i] >= 0);
if (pi[i] == 0) dp[i] = infty;
else dp[i] = min(infty,dp[i-pi[i]]+1);
}
FOR(i,1,Q){
int N; cin >> N;
if (dp[N] == infty) cout << "oo" << '\n';
else cout << dp[N] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
199 ms |
157072 KB |
Output is correct |
2 |
Correct |
234 ms |
156920 KB |
Output is correct |
3 |
Correct |
209 ms |
156796 KB |
Output is correct |
4 |
Correct |
198 ms |
156920 KB |
Output is correct |
5 |
Correct |
215 ms |
156920 KB |
Output is correct |
6 |
Correct |
198 ms |
156920 KB |
Output is correct |
7 |
Correct |
209 ms |
156920 KB |
Output is correct |
8 |
Correct |
219 ms |
156924 KB |
Output is correct |
9 |
Correct |
249 ms |
156920 KB |
Output is correct |
10 |
Correct |
282 ms |
156920 KB |
Output is correct |
11 |
Correct |
262 ms |
156920 KB |
Output is correct |
12 |
Correct |
195 ms |
156920 KB |
Output is correct |
13 |
Correct |
424 ms |
156988 KB |
Output is correct |
14 |
Correct |
407 ms |
156920 KB |
Output is correct |
15 |
Correct |
246 ms |
156920 KB |
Output is correct |
16 |
Correct |
234 ms |
156920 KB |
Output is correct |
17 |
Correct |
235 ms |
157048 KB |
Output is correct |
18 |
Correct |
198 ms |
156920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
156920 KB |
Output is correct |
2 |
Correct |
258 ms |
157304 KB |
Output is correct |
3 |
Correct |
500 ms |
157176 KB |
Output is correct |
4 |
Correct |
262 ms |
157016 KB |
Output is correct |
5 |
Correct |
375 ms |
157048 KB |
Output is correct |
6 |
Correct |
225 ms |
156924 KB |
Output is correct |
7 |
Correct |
223 ms |
156924 KB |
Output is correct |
8 |
Correct |
252 ms |
156920 KB |
Output is correct |
9 |
Correct |
437 ms |
157432 KB |
Output is correct |
10 |
Correct |
503 ms |
157176 KB |
Output is correct |
11 |
Correct |
498 ms |
157044 KB |
Output is correct |
12 |
Correct |
311 ms |
156920 KB |
Output is correct |
13 |
Correct |
210 ms |
156920 KB |
Output is correct |
14 |
Correct |
256 ms |
156920 KB |
Output is correct |
15 |
Correct |
432 ms |
157176 KB |
Output is correct |
16 |
Correct |
256 ms |
157280 KB |
Output is correct |
17 |
Correct |
445 ms |
157052 KB |
Output is correct |
18 |
Correct |
446 ms |
157304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
452 ms |
157176 KB |
Output is correct |
2 |
Correct |
540 ms |
157176 KB |
Output is correct |
3 |
Correct |
547 ms |
157304 KB |
Output is correct |
4 |
Correct |
346 ms |
157176 KB |
Output is correct |
5 |
Correct |
295 ms |
157560 KB |
Output is correct |
6 |
Correct |
439 ms |
157176 KB |
Output is correct |
7 |
Correct |
416 ms |
157400 KB |
Output is correct |
8 |
Correct |
442 ms |
157176 KB |
Output is correct |
9 |
Correct |
450 ms |
157176 KB |
Output is correct |
10 |
Correct |
362 ms |
156920 KB |
Output is correct |
11 |
Correct |
326 ms |
157048 KB |
Output is correct |
12 |
Correct |
409 ms |
156920 KB |
Output is correct |
13 |
Correct |
499 ms |
157304 KB |
Output is correct |
14 |
Correct |
317 ms |
157432 KB |
Output is correct |
15 |
Correct |
437 ms |
157096 KB |
Output is correct |
16 |
Correct |
465 ms |
157048 KB |
Output is correct |
17 |
Correct |
413 ms |
157176 KB |
Output is correct |
18 |
Correct |
535 ms |
157304 KB |
Output is correct |
19 |
Correct |
224 ms |
156920 KB |
Output is correct |
20 |
Correct |
531 ms |
157204 KB |
Output is correct |
21 |
Correct |
348 ms |
157560 KB |
Output is correct |
22 |
Correct |
546 ms |
157432 KB |
Output is correct |
23 |
Correct |
286 ms |
157176 KB |
Output is correct |
24 |
Correct |
243 ms |
157304 KB |
Output is correct |
25 |
Correct |
377 ms |
157304 KB |
Output is correct |
26 |
Correct |
345 ms |
157176 KB |
Output is correct |
27 |
Correct |
566 ms |
157432 KB |
Output is correct |
28 |
Correct |
248 ms |
157232 KB |
Output is correct |
29 |
Correct |
511 ms |
157688 KB |
Output is correct |
30 |
Correct |
480 ms |
157392 KB |
Output is correct |
31 |
Correct |
270 ms |
157196 KB |
Output is correct |
32 |
Correct |
300 ms |
157192 KB |
Output is correct |
33 |
Correct |
222 ms |
157176 KB |
Output is correct |
34 |
Correct |
414 ms |
157432 KB |
Output is correct |
35 |
Correct |
256 ms |
157304 KB |
Output is correct |
36 |
Correct |
527 ms |
157432 KB |
Output is correct |
37 |
Correct |
315 ms |
157436 KB |
Output is correct |
38 |
Correct |
444 ms |
157304 KB |
Output is correct |
39 |
Correct |
261 ms |
157176 KB |
Output is correct |
40 |
Correct |
400 ms |
157280 KB |
Output is correct |
41 |
Correct |
362 ms |
157432 KB |
Output is correct |
42 |
Correct |
481 ms |
157560 KB |
Output is correct |