#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
int ma[20000001];
int dp[20000001];
//vector<int> fac[20000001];
int main(){
memset(ma,0,sizeof(ma));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,s;
cin>>n>>s;
int aa;
int it[n];
for(int i=0;i<n;i++){
cin>>it[i];
}
sort(it,it+n);
for(int i=0;i<n;i++){
for(int j=it[i];j<20000001;j+=it[i]){
ma[j-1]=it[i]-1;
}
}
for(int i=10000000-1;i>=0;i--){
ma[i]=max(ma[i],ma[i+1]-1);
}
dp[0]=0;
for(int j=1;j<20000001;j++){
if(ma[j]==0){
dp[j]=-1;
}
else if(dp[j-ma[j]]!=-1){
dp[j]=dp[j-ma[j]]+1;
}
else{
dp[j]=-1;
}
}
while(s--){
cin>>aa;
if(dp[aa]==-1){
cout<<"oo"<<endl;
}
else{
cout<<dp[aa]<<endl;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
156920 KB |
Output is correct |
2 |
Correct |
201 ms |
156920 KB |
Output is correct |
3 |
Correct |
182 ms |
156920 KB |
Output is correct |
4 |
Correct |
159 ms |
156928 KB |
Output is correct |
5 |
Correct |
202 ms |
156920 KB |
Output is correct |
6 |
Correct |
178 ms |
156868 KB |
Output is correct |
7 |
Correct |
179 ms |
157048 KB |
Output is correct |
8 |
Correct |
186 ms |
156896 KB |
Output is correct |
9 |
Correct |
220 ms |
156920 KB |
Output is correct |
10 |
Correct |
254 ms |
156920 KB |
Output is correct |
11 |
Correct |
252 ms |
156920 KB |
Output is correct |
12 |
Correct |
154 ms |
156920 KB |
Output is correct |
13 |
Correct |
380 ms |
156920 KB |
Output is correct |
14 |
Correct |
383 ms |
156872 KB |
Output is correct |
15 |
Correct |
216 ms |
156920 KB |
Output is correct |
16 |
Correct |
197 ms |
156920 KB |
Output is correct |
17 |
Correct |
218 ms |
156920 KB |
Output is correct |
18 |
Correct |
159 ms |
156920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
157024 KB |
Output is correct |
2 |
Correct |
234 ms |
157304 KB |
Output is correct |
3 |
Correct |
472 ms |
157176 KB |
Output is correct |
4 |
Correct |
248 ms |
156920 KB |
Output is correct |
5 |
Correct |
363 ms |
157048 KB |
Output is correct |
6 |
Correct |
215 ms |
156920 KB |
Output is correct |
7 |
Correct |
208 ms |
156896 KB |
Output is correct |
8 |
Correct |
252 ms |
156920 KB |
Output is correct |
9 |
Correct |
411 ms |
157236 KB |
Output is correct |
10 |
Correct |
490 ms |
157176 KB |
Output is correct |
11 |
Incorrect |
477 ms |
157048 KB |
Output isn't correct |
12 |
Correct |
296 ms |
156920 KB |
Output is correct |
13 |
Correct |
197 ms |
157048 KB |
Output is correct |
14 |
Correct |
254 ms |
156920 KB |
Output is correct |
15 |
Correct |
402 ms |
157176 KB |
Output is correct |
16 |
Correct |
243 ms |
157176 KB |
Output is correct |
17 |
Correct |
399 ms |
156920 KB |
Output is correct |
18 |
Correct |
437 ms |
157432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
415 ms |
157436 KB |
Output is correct |
2 |
Correct |
482 ms |
157176 KB |
Output is correct |
3 |
Correct |
504 ms |
157304 KB |
Output is correct |
4 |
Incorrect |
332 ms |
157176 KB |
Output isn't correct |
5 |
Incorrect |
260 ms |
157432 KB |
Output isn't correct |
6 |
Correct |
420 ms |
157304 KB |
Output is correct |
7 |
Correct |
407 ms |
157560 KB |
Output is correct |
8 |
Correct |
407 ms |
157304 KB |
Output is correct |
9 |
Correct |
426 ms |
157200 KB |
Output is correct |
10 |
Correct |
357 ms |
156924 KB |
Output is correct |
11 |
Incorrect |
319 ms |
157048 KB |
Output isn't correct |
12 |
Correct |
378 ms |
156924 KB |
Output is correct |
13 |
Correct |
503 ms |
157304 KB |
Output is correct |
14 |
Correct |
288 ms |
157560 KB |
Output is correct |
15 |
Incorrect |
386 ms |
156920 KB |
Output isn't correct |
16 |
Correct |
439 ms |
157048 KB |
Output is correct |
17 |
Correct |
394 ms |
157052 KB |
Output is correct |
18 |
Correct |
479 ms |
157176 KB |
Output is correct |
19 |
Incorrect |
193 ms |
156916 KB |
Output isn't correct |
20 |
Correct |
491 ms |
157304 KB |
Output is correct |
21 |
Incorrect |
319 ms |
157304 KB |
Output isn't correct |
22 |
Correct |
513 ms |
157560 KB |
Output is correct |
23 |
Correct |
268 ms |
157304 KB |
Output is correct |
24 |
Correct |
221 ms |
157164 KB |
Output is correct |
25 |
Incorrect |
361 ms |
157328 KB |
Output isn't correct |
26 |
Incorrect |
328 ms |
157176 KB |
Output isn't correct |
27 |
Correct |
548 ms |
157432 KB |
Output is correct |
28 |
Incorrect |
223 ms |
157240 KB |
Output isn't correct |
29 |
Correct |
501 ms |
157560 KB |
Output is correct |
30 |
Correct |
446 ms |
157412 KB |
Output is correct |
31 |
Correct |
263 ms |
157176 KB |
Output is correct |
32 |
Incorrect |
289 ms |
157176 KB |
Output isn't correct |
33 |
Incorrect |
197 ms |
157176 KB |
Output isn't correct |
34 |
Correct |
412 ms |
157484 KB |
Output is correct |
35 |
Incorrect |
254 ms |
157432 KB |
Output isn't correct |
36 |
Correct |
500 ms |
157560 KB |
Output is correct |
37 |
Incorrect |
265 ms |
157560 KB |
Output isn't correct |
38 |
Correct |
425 ms |
157304 KB |
Output is correct |
39 |
Incorrect |
243 ms |
157132 KB |
Output isn't correct |
40 |
Correct |
362 ms |
157176 KB |
Output is correct |
41 |
Correct |
351 ms |
157432 KB |
Output is correct |
42 |
Incorrect |
438 ms |
157304 KB |
Output isn't correct |