#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=20000000-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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
208 ms |
156920 KB |
Output is correct |
2 |
Correct |
235 ms |
156924 KB |
Output is correct |
3 |
Correct |
218 ms |
156920 KB |
Output is correct |
4 |
Correct |
201 ms |
156920 KB |
Output is correct |
5 |
Correct |
226 ms |
156880 KB |
Output is correct |
6 |
Correct |
206 ms |
156920 KB |
Output is correct |
7 |
Correct |
220 ms |
156920 KB |
Output is correct |
8 |
Correct |
229 ms |
156896 KB |
Output is correct |
9 |
Correct |
253 ms |
156920 KB |
Output is correct |
10 |
Correct |
283 ms |
156864 KB |
Output is correct |
11 |
Correct |
266 ms |
156920 KB |
Output is correct |
12 |
Correct |
197 ms |
156920 KB |
Output is correct |
13 |
Correct |
414 ms |
156876 KB |
Output is correct |
14 |
Correct |
413 ms |
156920 KB |
Output is correct |
15 |
Correct |
254 ms |
156836 KB |
Output is correct |
16 |
Correct |
237 ms |
156920 KB |
Output is correct |
17 |
Correct |
231 ms |
156920 KB |
Output is correct |
18 |
Correct |
200 ms |
156920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
223 ms |
157028 KB |
Output is correct |
2 |
Correct |
246 ms |
157236 KB |
Output is correct |
3 |
Correct |
502 ms |
157176 KB |
Output is correct |
4 |
Correct |
263 ms |
156920 KB |
Output is correct |
5 |
Correct |
388 ms |
157152 KB |
Output is correct |
6 |
Correct |
232 ms |
156920 KB |
Output is correct |
7 |
Correct |
222 ms |
157048 KB |
Output is correct |
8 |
Correct |
262 ms |
156920 KB |
Output is correct |
9 |
Correct |
428 ms |
157176 KB |
Output is correct |
10 |
Correct |
509 ms |
157176 KB |
Output is correct |
11 |
Correct |
503 ms |
157048 KB |
Output is correct |
12 |
Correct |
318 ms |
156920 KB |
Output is correct |
13 |
Correct |
217 ms |
156920 KB |
Output is correct |
14 |
Correct |
263 ms |
156908 KB |
Output is correct |
15 |
Correct |
421 ms |
157048 KB |
Output is correct |
16 |
Correct |
251 ms |
157176 KB |
Output is correct |
17 |
Correct |
440 ms |
156920 KB |
Output is correct |
18 |
Correct |
428 ms |
157296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
434 ms |
157296 KB |
Output is correct |
2 |
Correct |
508 ms |
157176 KB |
Output is correct |
3 |
Correct |
516 ms |
157204 KB |
Output is correct |
4 |
Correct |
354 ms |
157140 KB |
Output is correct |
5 |
Correct |
282 ms |
157560 KB |
Output is correct |
6 |
Correct |
437 ms |
157176 KB |
Output is correct |
7 |
Correct |
407 ms |
157432 KB |
Output is correct |
8 |
Correct |
435 ms |
157180 KB |
Output is correct |
9 |
Correct |
430 ms |
157304 KB |
Output is correct |
10 |
Correct |
362 ms |
157048 KB |
Output is correct |
11 |
Correct |
319 ms |
157176 KB |
Output is correct |
12 |
Correct |
399 ms |
156976 KB |
Output is correct |
13 |
Correct |
490 ms |
157304 KB |
Output is correct |
14 |
Correct |
327 ms |
157560 KB |
Output is correct |
15 |
Correct |
414 ms |
156920 KB |
Output is correct |
16 |
Correct |
472 ms |
157128 KB |
Output is correct |
17 |
Correct |
428 ms |
157176 KB |
Output is correct |
18 |
Correct |
512 ms |
157176 KB |
Output is correct |
19 |
Correct |
232 ms |
156920 KB |
Output is correct |
20 |
Correct |
520 ms |
157304 KB |
Output is correct |
21 |
Correct |
361 ms |
157560 KB |
Output is correct |
22 |
Correct |
524 ms |
157560 KB |
Output is correct |
23 |
Correct |
299 ms |
157332 KB |
Output is correct |
24 |
Correct |
250 ms |
157272 KB |
Output is correct |
25 |
Correct |
378 ms |
157304 KB |
Output is correct |
26 |
Correct |
345 ms |
157180 KB |
Output is correct |
27 |
Correct |
560 ms |
157432 KB |
Output is correct |
28 |
Correct |
250 ms |
157176 KB |
Output is correct |
29 |
Correct |
504 ms |
157560 KB |
Output is correct |
30 |
Correct |
462 ms |
157432 KB |
Output is correct |
31 |
Correct |
278 ms |
157176 KB |
Output is correct |
32 |
Correct |
309 ms |
157136 KB |
Output is correct |
33 |
Correct |
230 ms |
157176 KB |
Output is correct |
34 |
Correct |
399 ms |
157432 KB |
Output is correct |
35 |
Correct |
260 ms |
157304 KB |
Output is correct |
36 |
Correct |
517 ms |
157560 KB |
Output is correct |
37 |
Correct |
282 ms |
157432 KB |
Output is correct |
38 |
Correct |
438 ms |
157180 KB |
Output is correct |
39 |
Correct |
262 ms |
157180 KB |
Output is correct |
40 |
Correct |
388 ms |
157176 KB |
Output is correct |
41 |
Correct |
357 ms |
157560 KB |
Output is correct |
42 |
Correct |
468 ms |
157304 KB |
Output is correct |