#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define pii pair<int, int>
using namespace std;
const int mxN = 2e7;
const int mod = 1e9 + 7;
int m, Q, dp[mxN];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("Bai3.inp", "r", stdin);
//freopen("Bai3.out", "w", stdout);
cin >> m >> Q;
for(int i = 1; i <= m; ++i){
int p; cin >> p;
for(int j = p - 1; j < mxN; j += p){
dp[j] = max(dp[j], p - 1);
}
}
for(int i = mxN - 2; i >= 0; --i){
dp[i] = max(dp[i], dp[i + 1] - 1);
}
dp[0] = 0;
for(int i = 1; i < mxN; ++i){
if(dp[i] > 0){
dp[i] = 1 + dp[i - dp[i]];
}
else{
dp[i] = mod;
}
}
while(Q--){
int x; cin >> x;
if(dp[x] >= mxN) cout << "oo" << endl;
else cout << dp[x] << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
195 ms |
156860 KB |
Output is correct |
2 |
Correct |
241 ms |
156920 KB |
Output is correct |
3 |
Correct |
232 ms |
156852 KB |
Output is correct |
4 |
Correct |
204 ms |
156860 KB |
Output is correct |
5 |
Correct |
216 ms |
156868 KB |
Output is correct |
6 |
Correct |
213 ms |
156884 KB |
Output is correct |
7 |
Correct |
233 ms |
156856 KB |
Output is correct |
8 |
Correct |
240 ms |
156860 KB |
Output is correct |
9 |
Correct |
306 ms |
156772 KB |
Output is correct |
10 |
Correct |
301 ms |
156752 KB |
Output is correct |
11 |
Correct |
316 ms |
156968 KB |
Output is correct |
12 |
Correct |
193 ms |
156852 KB |
Output is correct |
13 |
Correct |
499 ms |
156860 KB |
Output is correct |
14 |
Correct |
458 ms |
156876 KB |
Output is correct |
15 |
Correct |
272 ms |
156860 KB |
Output is correct |
16 |
Correct |
240 ms |
156868 KB |
Output is correct |
17 |
Correct |
254 ms |
156876 KB |
Output is correct |
18 |
Correct |
198 ms |
156780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
257 ms |
156900 KB |
Output is correct |
2 |
Correct |
254 ms |
156860 KB |
Output is correct |
3 |
Correct |
691 ms |
156856 KB |
Output is correct |
4 |
Correct |
258 ms |
156736 KB |
Output is correct |
5 |
Correct |
437 ms |
156860 KB |
Output is correct |
6 |
Correct |
255 ms |
156932 KB |
Output is correct |
7 |
Correct |
240 ms |
156964 KB |
Output is correct |
8 |
Correct |
266 ms |
156856 KB |
Output is correct |
9 |
Correct |
498 ms |
156864 KB |
Output is correct |
10 |
Correct |
612 ms |
156824 KB |
Output is correct |
11 |
Correct |
639 ms |
156748 KB |
Output is correct |
12 |
Correct |
350 ms |
156856 KB |
Output is correct |
13 |
Correct |
242 ms |
156796 KB |
Output is correct |
14 |
Correct |
258 ms |
156748 KB |
Output is correct |
15 |
Correct |
494 ms |
156960 KB |
Output is correct |
16 |
Correct |
242 ms |
156860 KB |
Output is correct |
17 |
Correct |
497 ms |
156952 KB |
Output is correct |
18 |
Correct |
454 ms |
156856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
490 ms |
156856 KB |
Output is correct |
2 |
Correct |
592 ms |
156876 KB |
Output is correct |
3 |
Correct |
594 ms |
157100 KB |
Output is correct |
4 |
Correct |
370 ms |
157100 KB |
Output is correct |
5 |
Correct |
275 ms |
156976 KB |
Output is correct |
6 |
Correct |
467 ms |
157116 KB |
Output is correct |
7 |
Correct |
413 ms |
156856 KB |
Output is correct |
8 |
Correct |
513 ms |
156856 KB |
Output is correct |
9 |
Correct |
504 ms |
156912 KB |
Output is correct |
10 |
Correct |
370 ms |
156796 KB |
Output is correct |
11 |
Correct |
338 ms |
156860 KB |
Output is correct |
12 |
Correct |
430 ms |
156920 KB |
Output is correct |
13 |
Correct |
552 ms |
157120 KB |
Output is correct |
14 |
Correct |
353 ms |
157368 KB |
Output is correct |
15 |
Correct |
471 ms |
156872 KB |
Output is correct |
16 |
Correct |
522 ms |
156896 KB |
Output is correct |
17 |
Correct |
449 ms |
156856 KB |
Output is correct |
18 |
Correct |
672 ms |
156860 KB |
Output is correct |
19 |
Correct |
243 ms |
156872 KB |
Output is correct |
20 |
Correct |
658 ms |
156984 KB |
Output is correct |
21 |
Correct |
408 ms |
157376 KB |
Output is correct |
22 |
Correct |
666 ms |
157044 KB |
Output is correct |
23 |
Correct |
328 ms |
156988 KB |
Output is correct |
24 |
Correct |
259 ms |
157132 KB |
Output is correct |
25 |
Correct |
414 ms |
157160 KB |
Output is correct |
26 |
Correct |
374 ms |
157108 KB |
Output is correct |
27 |
Correct |
699 ms |
156868 KB |
Output is correct |
28 |
Correct |
287 ms |
157120 KB |
Output is correct |
29 |
Correct |
584 ms |
156988 KB |
Output is correct |
30 |
Correct |
557 ms |
156988 KB |
Output is correct |
31 |
Correct |
291 ms |
156984 KB |
Output is correct |
32 |
Correct |
337 ms |
157160 KB |
Output is correct |
33 |
Correct |
221 ms |
157116 KB |
Output is correct |
34 |
Correct |
407 ms |
156888 KB |
Output is correct |
35 |
Correct |
264 ms |
157132 KB |
Output is correct |
36 |
Correct |
559 ms |
156980 KB |
Output is correct |
37 |
Correct |
285 ms |
156984 KB |
Output is correct |
38 |
Correct |
477 ms |
157060 KB |
Output is correct |
39 |
Correct |
249 ms |
157100 KB |
Output is correct |
40 |
Correct |
430 ms |
157112 KB |
Output is correct |
41 |
Correct |
377 ms |
156864 KB |
Output is correct |
42 |
Correct |
556 ms |
157256 KB |
Output is correct |