#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++){
dp[i]=(i>=jump[i]&&jump[i]!=0?min(INF,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 |
Incorrect |
148 ms |
188396 KB |
Output isn't correct |
2 |
Correct |
174 ms |
188364 KB |
Output is correct |
3 |
Correct |
164 ms |
188140 KB |
Output is correct |
4 |
Correct |
149 ms |
188268 KB |
Output is correct |
5 |
Correct |
160 ms |
188396 KB |
Output is correct |
6 |
Incorrect |
148 ms |
188396 KB |
Output isn't correct |
7 |
Correct |
162 ms |
188268 KB |
Output is correct |
8 |
Correct |
172 ms |
188268 KB |
Output is correct |
9 |
Correct |
196 ms |
188140 KB |
Output is correct |
10 |
Correct |
221 ms |
188140 KB |
Output is correct |
11 |
Correct |
207 ms |
188140 KB |
Output is correct |
12 |
Correct |
144 ms |
188396 KB |
Output is correct |
13 |
Correct |
328 ms |
188268 KB |
Output is correct |
14 |
Correct |
330 ms |
188268 KB |
Output is correct |
15 |
Correct |
183 ms |
188140 KB |
Output is correct |
16 |
Correct |
174 ms |
188268 KB |
Output is correct |
17 |
Correct |
170 ms |
188396 KB |
Output is correct |
18 |
Correct |
146 ms |
188268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
188268 KB |
Output is correct |
2 |
Correct |
180 ms |
188268 KB |
Output is correct |
3 |
Correct |
400 ms |
188140 KB |
Output is correct |
4 |
Correct |
192 ms |
188268 KB |
Output is correct |
5 |
Correct |
286 ms |
188140 KB |
Output is correct |
6 |
Correct |
166 ms |
188236 KB |
Output is correct |
7 |
Correct |
163 ms |
188140 KB |
Output is correct |
8 |
Correct |
183 ms |
188140 KB |
Output is correct |
9 |
Correct |
319 ms |
188268 KB |
Output is correct |
10 |
Correct |
402 ms |
188140 KB |
Output is correct |
11 |
Correct |
387 ms |
188140 KB |
Output is correct |
12 |
Correct |
237 ms |
188140 KB |
Output is correct |
13 |
Correct |
152 ms |
188140 KB |
Output is correct |
14 |
Correct |
190 ms |
188268 KB |
Output is correct |
15 |
Correct |
330 ms |
188140 KB |
Output is correct |
16 |
Correct |
181 ms |
188140 KB |
Output is correct |
17 |
Correct |
336 ms |
188140 KB |
Output is correct |
18 |
Correct |
338 ms |
188268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
188268 KB |
Output is correct |
2 |
Correct |
405 ms |
188396 KB |
Output is correct |
3 |
Correct |
410 ms |
188512 KB |
Output is correct |
4 |
Correct |
271 ms |
188524 KB |
Output is correct |
5 |
Correct |
220 ms |
188396 KB |
Output is correct |
6 |
Correct |
342 ms |
188652 KB |
Output is correct |
7 |
Correct |
298 ms |
188396 KB |
Output is correct |
8 |
Correct |
350 ms |
188288 KB |
Output is correct |
9 |
Correct |
347 ms |
188288 KB |
Output is correct |
10 |
Correct |
271 ms |
188268 KB |
Output is correct |
11 |
Correct |
235 ms |
188268 KB |
Output is correct |
12 |
Correct |
314 ms |
188268 KB |
Output is correct |
13 |
Correct |
383 ms |
188524 KB |
Output is correct |
14 |
Correct |
250 ms |
188780 KB |
Output is correct |
15 |
Correct |
330 ms |
188344 KB |
Output is correct |
16 |
Correct |
379 ms |
188396 KB |
Output is correct |
17 |
Correct |
321 ms |
188408 KB |
Output is correct |
18 |
Correct |
413 ms |
188268 KB |
Output is correct |
19 |
Correct |
167 ms |
188268 KB |
Output is correct |
20 |
Correct |
416 ms |
188524 KB |
Output is correct |
21 |
Correct |
289 ms |
188780 KB |
Output is correct |
22 |
Correct |
424 ms |
188524 KB |
Output is correct |
23 |
Correct |
222 ms |
188396 KB |
Output is correct |
24 |
Correct |
186 ms |
188524 KB |
Output is correct |
25 |
Correct |
288 ms |
188652 KB |
Output is correct |
26 |
Correct |
272 ms |
188524 KB |
Output is correct |
27 |
Correct |
451 ms |
188396 KB |
Output is correct |
28 |
Correct |
182 ms |
188524 KB |
Output is correct |
29 |
Correct |
386 ms |
188396 KB |
Output is correct |
30 |
Correct |
359 ms |
188396 KB |
Output is correct |
31 |
Correct |
209 ms |
188516 KB |
Output is correct |
32 |
Correct |
224 ms |
188524 KB |
Output is correct |
33 |
Correct |
173 ms |
188396 KB |
Output is correct |
34 |
Correct |
296 ms |
188396 KB |
Output is correct |
35 |
Correct |
188 ms |
188524 KB |
Output is correct |
36 |
Correct |
413 ms |
188524 KB |
Output is correct |
37 |
Correct |
222 ms |
188524 KB |
Output is correct |
38 |
Correct |
346 ms |
188652 KB |
Output is correct |
39 |
Correct |
197 ms |
188648 KB |
Output is correct |
40 |
Correct |
302 ms |
188524 KB |
Output is correct |
41 |
Correct |
274 ms |
188268 KB |
Output is correct |
42 |
Correct |
372 ms |
188652 KB |
Output is correct |