#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N=12e6+5;
const ll INF=1e9+1;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define lwb lower_bound
ll m,q,x,jump[N],dp[N];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>m>>q;
REP(i,m){
cin>>x;
for(int j=x-1;j<N;j+=x){
jump[j]=x-1;
}
}
for(int i=N-2;i>=1;i--){
jump[i]=max(jump[i],jump[i+1]-1);
}
for(int i=1;i<N;i++){
if(jump[i]==0)dp[i]=INF;
else dp[i]=min(dp[i-jump[i]]+1,INF);
}
while(q--){
cin>>x;
if(dp[x]>x){
cout<<"oo\n";
}else{
cout<<dp[x]<<"\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
188268 KB |
Output is correct |
2 |
Correct |
183 ms |
188140 KB |
Output is correct |
3 |
Correct |
169 ms |
188268 KB |
Output is correct |
4 |
Correct |
158 ms |
188228 KB |
Output is correct |
5 |
Correct |
183 ms |
188140 KB |
Output is correct |
6 |
Correct |
151 ms |
188172 KB |
Output is correct |
7 |
Correct |
176 ms |
188140 KB |
Output is correct |
8 |
Correct |
203 ms |
188268 KB |
Output is correct |
9 |
Correct |
203 ms |
188192 KB |
Output is correct |
10 |
Correct |
225 ms |
188168 KB |
Output is correct |
11 |
Correct |
226 ms |
188268 KB |
Output is correct |
12 |
Correct |
161 ms |
188268 KB |
Output is correct |
13 |
Correct |
371 ms |
188172 KB |
Output is correct |
14 |
Correct |
330 ms |
188304 KB |
Output is correct |
15 |
Correct |
186 ms |
188140 KB |
Output is correct |
16 |
Correct |
175 ms |
188140 KB |
Output is correct |
17 |
Correct |
171 ms |
188396 KB |
Output is correct |
18 |
Correct |
146 ms |
188268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
164 ms |
188396 KB |
Output is correct |
2 |
Correct |
184 ms |
188652 KB |
Output is correct |
3 |
Correct |
396 ms |
188524 KB |
Output is correct |
4 |
Correct |
186 ms |
188268 KB |
Output is correct |
5 |
Correct |
286 ms |
188524 KB |
Output is correct |
6 |
Correct |
168 ms |
188268 KB |
Output is correct |
7 |
Correct |
167 ms |
188268 KB |
Output is correct |
8 |
Correct |
186 ms |
188268 KB |
Output is correct |
9 |
Correct |
322 ms |
188672 KB |
Output is correct |
10 |
Correct |
395 ms |
188652 KB |
Output is correct |
11 |
Correct |
386 ms |
188524 KB |
Output is correct |
12 |
Correct |
234 ms |
188268 KB |
Output is correct |
13 |
Correct |
152 ms |
188268 KB |
Output is correct |
14 |
Correct |
186 ms |
188176 KB |
Output is correct |
15 |
Correct |
330 ms |
188652 KB |
Output is correct |
16 |
Correct |
186 ms |
188524 KB |
Output is correct |
17 |
Correct |
340 ms |
188252 KB |
Output is correct |
18 |
Correct |
332 ms |
188524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
345 ms |
188780 KB |
Output is correct |
2 |
Correct |
408 ms |
188652 KB |
Output is correct |
3 |
Correct |
409 ms |
188908 KB |
Output is correct |
4 |
Correct |
271 ms |
188908 KB |
Output is correct |
5 |
Correct |
223 ms |
188780 KB |
Output is correct |
6 |
Correct |
352 ms |
188908 KB |
Output is correct |
7 |
Correct |
299 ms |
188780 KB |
Output is correct |
8 |
Correct |
350 ms |
188652 KB |
Output is correct |
9 |
Correct |
354 ms |
188672 KB |
Output is correct |
10 |
Correct |
274 ms |
188396 KB |
Output is correct |
11 |
Correct |
235 ms |
188544 KB |
Output is correct |
12 |
Correct |
315 ms |
188524 KB |
Output is correct |
13 |
Correct |
388 ms |
189036 KB |
Output is correct |
14 |
Correct |
249 ms |
189292 KB |
Output is correct |
15 |
Correct |
332 ms |
188652 KB |
Output is correct |
16 |
Correct |
369 ms |
188524 KB |
Output is correct |
17 |
Correct |
319 ms |
188652 KB |
Output is correct |
18 |
Correct |
406 ms |
188780 KB |
Output is correct |
19 |
Correct |
166 ms |
188396 KB |
Output is correct |
20 |
Correct |
413 ms |
188780 KB |
Output is correct |
21 |
Correct |
286 ms |
189164 KB |
Output is correct |
22 |
Correct |
422 ms |
188928 KB |
Output is correct |
23 |
Correct |
223 ms |
188908 KB |
Output is correct |
24 |
Correct |
184 ms |
188908 KB |
Output is correct |
25 |
Correct |
290 ms |
188908 KB |
Output is correct |
26 |
Correct |
273 ms |
188908 KB |
Output is correct |
27 |
Correct |
449 ms |
188672 KB |
Output is correct |
28 |
Correct |
185 ms |
188908 KB |
Output is correct |
29 |
Correct |
391 ms |
188796 KB |
Output is correct |
30 |
Correct |
357 ms |
188780 KB |
Output is correct |
31 |
Correct |
210 ms |
188512 KB |
Output is correct |
32 |
Correct |
224 ms |
188524 KB |
Output is correct |
33 |
Correct |
171 ms |
188396 KB |
Output is correct |
34 |
Correct |
301 ms |
188268 KB |
Output is correct |
35 |
Correct |
188 ms |
188524 KB |
Output is correct |
36 |
Correct |
413 ms |
188652 KB |
Output is correct |
37 |
Correct |
229 ms |
188396 KB |
Output is correct |
38 |
Correct |
355 ms |
188652 KB |
Output is correct |
39 |
Correct |
198 ms |
188524 KB |
Output is correct |
40 |
Correct |
301 ms |
188396 KB |
Output is correct |
41 |
Correct |
276 ms |
188396 KB |
Output is correct |
42 |
Correct |
370 ms |
188672 KB |
Output is correct |