#include<bits/stdc++.h>
using namespace std;
const int N=1e7+5;
int m,q;
int mx;
int p[N],dp[N];
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> m >> q;
for(int i=0;i<m;i++){
int x;
cin >> x;
for(int i=0;i<N;i+=x)p[i]=max(p[i],x);
}
for(int l=0,r=0,cnt=0;l<N&&l<=r;l=r+1,r=min(mx,N-1),cnt++){
for(int i=l;i<=r;i++){
dp[i]=cnt;
mx=max(mx,i+p[i]-1);
}
}
while(q--){
int n;
cin >> n;
if(n>mx)cout << "oo\n";
else cout << dp[n] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
39456 KB |
Output is correct |
2 |
Correct |
62 ms |
78832 KB |
Output is correct |
3 |
Correct |
37 ms |
41648 KB |
Output is correct |
4 |
Correct |
42 ms |
78672 KB |
Output is correct |
5 |
Correct |
46 ms |
78676 KB |
Output is correct |
6 |
Correct |
25 ms |
39592 KB |
Output is correct |
7 |
Correct |
36 ms |
41648 KB |
Output is correct |
8 |
Correct |
39 ms |
43860 KB |
Output is correct |
9 |
Correct |
66 ms |
78676 KB |
Output is correct |
10 |
Correct |
86 ms |
78492 KB |
Output is correct |
11 |
Correct |
70 ms |
78676 KB |
Output is correct |
12 |
Correct |
43 ms |
78596 KB |
Output is correct |
13 |
Correct |
156 ms |
78676 KB |
Output is correct |
14 |
Correct |
142 ms |
78496 KB |
Output is correct |
15 |
Correct |
71 ms |
78508 KB |
Output is correct |
16 |
Correct |
55 ms |
78676 KB |
Output is correct |
17 |
Correct |
55 ms |
78492 KB |
Output is correct |
18 |
Correct |
50 ms |
78712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
78676 KB |
Output is correct |
2 |
Correct |
74 ms |
78508 KB |
Output is correct |
3 |
Correct |
208 ms |
78496 KB |
Output is correct |
4 |
Correct |
75 ms |
78492 KB |
Output is correct |
5 |
Correct |
131 ms |
78492 KB |
Output is correct |
6 |
Correct |
62 ms |
78516 KB |
Output is correct |
7 |
Correct |
64 ms |
78464 KB |
Output is correct |
8 |
Correct |
78 ms |
78644 KB |
Output is correct |
9 |
Correct |
150 ms |
78672 KB |
Output is correct |
10 |
Correct |
209 ms |
78676 KB |
Output is correct |
11 |
Correct |
193 ms |
78492 KB |
Output is correct |
12 |
Correct |
95 ms |
78676 KB |
Output is correct |
13 |
Correct |
49 ms |
78672 KB |
Output is correct |
14 |
Correct |
66 ms |
78496 KB |
Output is correct |
15 |
Correct |
155 ms |
78500 KB |
Output is correct |
16 |
Correct |
66 ms |
78680 KB |
Output is correct |
17 |
Correct |
158 ms |
78492 KB |
Output is correct |
18 |
Correct |
156 ms |
78492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
78756 KB |
Output is correct |
2 |
Correct |
191 ms |
78676 KB |
Output is correct |
3 |
Correct |
192 ms |
78768 KB |
Output is correct |
4 |
Correct |
127 ms |
79028 KB |
Output is correct |
5 |
Correct |
90 ms |
78748 KB |
Output is correct |
6 |
Correct |
164 ms |
78824 KB |
Output is correct |
7 |
Correct |
156 ms |
78904 KB |
Output is correct |
8 |
Correct |
157 ms |
78692 KB |
Output is correct |
9 |
Correct |
148 ms |
78676 KB |
Output is correct |
10 |
Correct |
113 ms |
78500 KB |
Output is correct |
11 |
Correct |
102 ms |
78928 KB |
Output is correct |
12 |
Correct |
140 ms |
78752 KB |
Output is correct |
13 |
Correct |
192 ms |
78764 KB |
Output is correct |
14 |
Correct |
94 ms |
79200 KB |
Output is correct |
15 |
Correct |
139 ms |
78748 KB |
Output is correct |
16 |
Correct |
166 ms |
78748 KB |
Output is correct |
17 |
Correct |
145 ms |
78676 KB |
Output is correct |
18 |
Correct |
219 ms |
78676 KB |
Output is correct |
19 |
Correct |
58 ms |
78716 KB |
Output is correct |
20 |
Correct |
203 ms |
78676 KB |
Output is correct |
21 |
Correct |
123 ms |
79264 KB |
Output is correct |
22 |
Correct |
198 ms |
78676 KB |
Output is correct |
23 |
Correct |
97 ms |
78932 KB |
Output is correct |
24 |
Correct |
69 ms |
78932 KB |
Output is correct |
25 |
Correct |
136 ms |
78928 KB |
Output is correct |
26 |
Correct |
125 ms |
78920 KB |
Output is correct |
27 |
Correct |
228 ms |
78752 KB |
Output is correct |
28 |
Correct |
63 ms |
78912 KB |
Output is correct |
29 |
Correct |
211 ms |
78672 KB |
Output is correct |
30 |
Correct |
188 ms |
78928 KB |
Output is correct |
31 |
Correct |
87 ms |
78856 KB |
Output is correct |
32 |
Correct |
97 ms |
78944 KB |
Output is correct |
33 |
Correct |
61 ms |
78744 KB |
Output is correct |
34 |
Correct |
144 ms |
78672 KB |
Output is correct |
35 |
Correct |
70 ms |
78988 KB |
Output is correct |
36 |
Correct |
211 ms |
78756 KB |
Output is correct |
37 |
Correct |
87 ms |
78672 KB |
Output is correct |
38 |
Correct |
160 ms |
78928 KB |
Output is correct |
39 |
Correct |
87 ms |
78768 KB |
Output is correct |
40 |
Correct |
152 ms |
78760 KB |
Output is correct |
41 |
Correct |
142 ms |
78932 KB |
Output is correct |
42 |
Correct |
183 ms |
78932 KB |
Output is correct |