#include <iostream>
using namespace std;
const int MAXN = 2e5+5;
const int MAXN2 = 1e7+5;
int arr[MAXN];
int dp[MAXN2];
int dp2[MAXN2];
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
for(int i=0;i<arr[n];i++){
dp[i] = 1;
}
for(int i=arr[n];i<MAXN;i++){
dp[i] = 1e9;
}
for(int i=1;i<=n;i++){
for(int j=arr[i]-1;j<MAXN;j+=arr[i]){
dp2[j] = max(dp2[j],arr[i]-1);
//cout<<j<<" "<<dp2[j]<<endl;
}
}
for(int i=MAXN-1;i>=0;i--){
dp2[i] = max(dp2[i],dp2[i+1]-1);
}
for(int i=arr[n];i<MAXN;i++){
dp[i] = min(dp[i],dp[i-dp2[i]]+1);
}
for(int i=1;i<=m;i++){
int x;
cin>>x;
if(dp[x]==1e9){
cout<<"oo"<<endl;
}else{
cout<<dp[x]<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1912 KB |
Output is correct |
2 |
Correct |
7 ms |
1916 KB |
Output is correct |
3 |
Correct |
6 ms |
1912 KB |
Output is correct |
4 |
Correct |
35 ms |
2040 KB |
Output is correct |
5 |
Correct |
6 ms |
1912 KB |
Output is correct |
6 |
Correct |
9 ms |
1912 KB |
Output is correct |
7 |
Correct |
6 ms |
1912 KB |
Output is correct |
8 |
Correct |
11 ms |
1912 KB |
Output is correct |
9 |
Correct |
6 ms |
1912 KB |
Output is correct |
10 |
Correct |
9 ms |
1912 KB |
Output is correct |
11 |
Correct |
9 ms |
1912 KB |
Output is correct |
12 |
Correct |
5 ms |
1912 KB |
Output is correct |
13 |
Correct |
10 ms |
1912 KB |
Output is correct |
14 |
Correct |
34 ms |
2040 KB |
Output is correct |
15 |
Correct |
6 ms |
1916 KB |
Output is correct |
16 |
Correct |
7 ms |
1912 KB |
Output is correct |
17 |
Correct |
36 ms |
1964 KB |
Output is correct |
18 |
Correct |
35 ms |
2168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
4732 KB |
Output isn't correct |
2 |
Incorrect |
90 ms |
37368 KB |
Output isn't correct |
3 |
Incorrect |
55 ms |
11640 KB |
Output isn't correct |
4 |
Incorrect |
7 ms |
1912 KB |
Output isn't correct |
5 |
Incorrect |
38 ms |
6908 KB |
Output isn't correct |
6 |
Incorrect |
5 ms |
1916 KB |
Output isn't correct |
7 |
Incorrect |
16 ms |
4856 KB |
Output isn't correct |
8 |
Incorrect |
6 ms |
1912 KB |
Output isn't correct |
9 |
Incorrect |
52 ms |
6952 KB |
Output isn't correct |
10 |
Incorrect |
60 ms |
11512 KB |
Output isn't correct |
11 |
Incorrect |
30 ms |
5112 KB |
Output isn't correct |
12 |
Incorrect |
6 ms |
1912 KB |
Output isn't correct |
13 |
Incorrect |
7 ms |
3064 KB |
Output isn't correct |
14 |
Incorrect |
7 ms |
1912 KB |
Output isn't correct |
15 |
Incorrect |
30 ms |
4728 KB |
Output isn't correct |
16 |
Incorrect |
90 ms |
37528 KB |
Output isn't correct |
17 |
Incorrect |
7 ms |
1912 KB |
Output isn't correct |
18 |
Incorrect |
80 ms |
21752 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
174 ms |
6128 KB |
Output isn't correct |
2 |
Incorrect |
127 ms |
4856 KB |
Output isn't correct |
3 |
Incorrect |
220 ms |
5968 KB |
Output isn't correct |
4 |
Incorrect |
307 ms |
2980 KB |
Output isn't correct |
5 |
Incorrect |
405 ms |
20720 KB |
Output isn't correct |
6 |
Incorrect |
332 ms |
3112 KB |
Output isn't correct |
7 |
Incorrect |
256 ms |
13928 KB |
Output isn't correct |
8 |
Incorrect |
176 ms |
6024 KB |
Output isn't correct |
9 |
Incorrect |
176 ms |
6056 KB |
Output isn't correct |
10 |
Incorrect |
55 ms |
2168 KB |
Output isn't correct |
11 |
Incorrect |
94 ms |
2296 KB |
Output isn't correct |
12 |
Incorrect |
92 ms |
2172 KB |
Output isn't correct |
13 |
Incorrect |
321 ms |
5504 KB |
Output isn't correct |
14 |
Incorrect |
319 ms |
2972 KB |
Output isn't correct |
15 |
Incorrect |
101 ms |
2296 KB |
Output isn't correct |
16 |
Incorrect |
90 ms |
2396 KB |
Output isn't correct |
17 |
Incorrect |
79 ms |
4984 KB |
Output isn't correct |
18 |
Incorrect |
126 ms |
4728 KB |
Output isn't correct |
19 |
Incorrect |
90 ms |
4220 KB |
Output isn't correct |
20 |
Incorrect |
217 ms |
6080 KB |
Output isn't correct |
21 |
Incorrect |
333 ms |
2952 KB |
Output isn't correct |
22 |
Incorrect |
398 ms |
9080 KB |
Output isn't correct |
23 |
Incorrect |
355 ms |
6400 KB |
Output isn't correct |
24 |
Incorrect |
329 ms |
2936 KB |
Output isn't correct |
25 |
Incorrect |
327 ms |
2960 KB |
Output isn't correct |
26 |
Incorrect |
311 ms |
2808 KB |
Output isn't correct |
27 |
Incorrect |
244 ms |
9292 KB |
Output isn't correct |
28 |
Incorrect |
333 ms |
2992 KB |
Output isn't correct |
29 |
Incorrect |
398 ms |
9208 KB |
Output isn't correct |
30 |
Incorrect |
384 ms |
6804 KB |
Output isn't correct |
31 |
Incorrect |
301 ms |
3192 KB |
Output isn't correct |
32 |
Incorrect |
320 ms |
2908 KB |
Output isn't correct |
33 |
Incorrect |
315 ms |
3004 KB |
Output isn't correct |
34 |
Incorrect |
250 ms |
13944 KB |
Output isn't correct |
35 |
Incorrect |
331 ms |
3124 KB |
Output isn't correct |
36 |
Incorrect |
401 ms |
9016 KB |
Output isn't correct |
37 |
Incorrect |
404 ms |
20776 KB |
Output isn't correct |
38 |
Incorrect |
324 ms |
2936 KB |
Output isn't correct |
39 |
Incorrect |
343 ms |
2936 KB |
Output isn't correct |
40 |
Incorrect |
329 ms |
3028 KB |
Output isn't correct |
41 |
Correct |
267 ms |
31608 KB |
Output is correct |
42 |
Incorrect |
330 ms |
2944 KB |
Output isn't correct |