#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[10000001];
int dp[10000001];
//vector<int> fac[10000001];
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<10000001;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<10000001;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 |
106 ms |
78584 KB |
Output is correct |
2 |
Correct |
121 ms |
78584 KB |
Output is correct |
3 |
Correct |
111 ms |
78584 KB |
Output is correct |
4 |
Correct |
102 ms |
78584 KB |
Output is correct |
5 |
Correct |
113 ms |
78584 KB |
Output is correct |
6 |
Correct |
107 ms |
78584 KB |
Output is correct |
7 |
Correct |
114 ms |
78584 KB |
Output is correct |
8 |
Correct |
115 ms |
78712 KB |
Output is correct |
9 |
Correct |
131 ms |
78584 KB |
Output is correct |
10 |
Correct |
144 ms |
78584 KB |
Output is correct |
11 |
Correct |
136 ms |
78584 KB |
Output is correct |
12 |
Correct |
101 ms |
78584 KB |
Output is correct |
13 |
Correct |
210 ms |
78584 KB |
Output is correct |
14 |
Correct |
210 ms |
78712 KB |
Output is correct |
15 |
Correct |
127 ms |
78584 KB |
Output is correct |
16 |
Correct |
120 ms |
78584 KB |
Output is correct |
17 |
Correct |
119 ms |
78584 KB |
Output is correct |
18 |
Correct |
105 ms |
78584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
78688 KB |
Output is correct |
2 |
Correct |
126 ms |
78968 KB |
Output is correct |
3 |
Correct |
249 ms |
78824 KB |
Output is correct |
4 |
Correct |
131 ms |
78584 KB |
Output is correct |
5 |
Correct |
186 ms |
78844 KB |
Output is correct |
6 |
Correct |
120 ms |
78584 KB |
Output is correct |
7 |
Correct |
115 ms |
78584 KB |
Output is correct |
8 |
Correct |
129 ms |
78568 KB |
Output is correct |
9 |
Correct |
215 ms |
78840 KB |
Output is correct |
10 |
Correct |
246 ms |
78840 KB |
Output is correct |
11 |
Incorrect |
239 ms |
78840 KB |
Output isn't correct |
12 |
Correct |
159 ms |
78584 KB |
Output is correct |
13 |
Correct |
109 ms |
78584 KB |
Output is correct |
14 |
Correct |
133 ms |
78584 KB |
Output is correct |
15 |
Correct |
211 ms |
78844 KB |
Output is correct |
16 |
Correct |
125 ms |
78968 KB |
Output is correct |
17 |
Correct |
214 ms |
78584 KB |
Output is correct |
18 |
Incorrect |
216 ms |
78968 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
224 ms |
78968 KB |
Output is correct |
2 |
Correct |
258 ms |
78840 KB |
Output is correct |
3 |
Correct |
263 ms |
78968 KB |
Output is correct |
4 |
Incorrect |
187 ms |
78840 KB |
Output isn't correct |
5 |
Incorrect |
152 ms |
79224 KB |
Output isn't correct |
6 |
Correct |
239 ms |
78876 KB |
Output is correct |
7 |
Correct |
207 ms |
79352 KB |
Output is correct |
8 |
Correct |
222 ms |
78840 KB |
Output is correct |
9 |
Correct |
223 ms |
78840 KB |
Output is correct |
10 |
Correct |
182 ms |
78840 KB |
Output is correct |
11 |
Incorrect |
161 ms |
78716 KB |
Output isn't correct |
12 |
Correct |
205 ms |
78712 KB |
Output is correct |
13 |
Correct |
251 ms |
79096 KB |
Output is correct |
14 |
Correct |
172 ms |
79224 KB |
Output is correct |
15 |
Incorrect |
214 ms |
78844 KB |
Output isn't correct |
16 |
Correct |
230 ms |
78840 KB |
Output is correct |
17 |
Correct |
209 ms |
78968 KB |
Output is correct |
18 |
Correct |
259 ms |
78968 KB |
Output is correct |
19 |
Incorrect |
119 ms |
78712 KB |
Output isn't correct |
20 |
Correct |
264 ms |
78968 KB |
Output is correct |
21 |
Incorrect |
198 ms |
79248 KB |
Output isn't correct |
22 |
Correct |
296 ms |
79224 KB |
Output is correct |
23 |
Correct |
161 ms |
78968 KB |
Output is correct |
24 |
Correct |
142 ms |
78968 KB |
Output is correct |
25 |
Incorrect |
201 ms |
79224 KB |
Output isn't correct |
26 |
Incorrect |
188 ms |
78840 KB |
Output isn't correct |
27 |
Correct |
284 ms |
79096 KB |
Output is correct |
28 |
Incorrect |
137 ms |
78968 KB |
Output isn't correct |
29 |
Correct |
271 ms |
79224 KB |
Output is correct |
30 |
Correct |
254 ms |
79092 KB |
Output is correct |
31 |
Correct |
152 ms |
78968 KB |
Output is correct |
32 |
Incorrect |
164 ms |
79096 KB |
Output isn't correct |
33 |
Incorrect |
134 ms |
78968 KB |
Output isn't correct |
34 |
Correct |
212 ms |
79100 KB |
Output is correct |
35 |
Incorrect |
142 ms |
78968 KB |
Output isn't correct |
36 |
Correct |
273 ms |
79176 KB |
Output is correct |
37 |
Incorrect |
158 ms |
79224 KB |
Output isn't correct |
38 |
Correct |
233 ms |
78848 KB |
Output is correct |
39 |
Incorrect |
149 ms |
79016 KB |
Output isn't correct |
40 |
Correct |
209 ms |
79096 KB |
Output is correct |
41 |
Correct |
185 ms |
79096 KB |
Output is correct |
42 |
Incorrect |
252 ms |
78968 KB |
Output isn't correct |