#include <bits/stdc++.h>
#define N 100050
using namespace std;
int n, q, p[N], dp[10000005], prox[10000005], pr[N], lim;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>q;
for(int i = 1; i <= n; i++)
{
cin>>p[i];
for(int j = p[i]; j < 10000005; j+= p[i]) pr[j] = p[i];
}
pr[0] = p[n];
dp[0] = 1;
for(int i = 0; i < 10000005; i++)
{
if(!dp[i]) continue;
for(int j = lim + 1; j < min(10000005, i + pr[i]); j++) dp[j] = dp[i] + 1;
lim = max(lim, min(10000005, i + pr[i]) - 1);
}
for(int i = 1, x; i <= q; i++)
{
cin>>x;
if(!dp[x]) cout<<"oo\n";
else cout<<dp[x] - 1<<"\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
39544 KB |
Output is correct |
2 |
Correct |
141 ms |
78708 KB |
Output is correct |
3 |
Correct |
70 ms |
78708 KB |
Output is correct |
4 |
Correct |
95 ms |
78944 KB |
Output is correct |
5 |
Correct |
134 ms |
78944 KB |
Output is correct |
6 |
Correct |
57 ms |
78944 KB |
Output is correct |
7 |
Correct |
75 ms |
78944 KB |
Output is correct |
8 |
Correct |
84 ms |
78944 KB |
Output is correct |
9 |
Correct |
149 ms |
78944 KB |
Output is correct |
10 |
Correct |
178 ms |
78944 KB |
Output is correct |
11 |
Correct |
164 ms |
78944 KB |
Output is correct |
12 |
Correct |
102 ms |
78944 KB |
Output is correct |
13 |
Correct |
290 ms |
78944 KB |
Output is correct |
14 |
Correct |
290 ms |
78956 KB |
Output is correct |
15 |
Correct |
139 ms |
78956 KB |
Output is correct |
16 |
Correct |
140 ms |
78956 KB |
Output is correct |
17 |
Correct |
145 ms |
79000 KB |
Output is correct |
18 |
Correct |
99 ms |
79000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
79000 KB |
Output is correct |
2 |
Correct |
149 ms |
79352 KB |
Output is correct |
3 |
Correct |
414 ms |
79352 KB |
Output is correct |
4 |
Correct |
149 ms |
79352 KB |
Output is correct |
5 |
Correct |
254 ms |
79352 KB |
Output is correct |
6 |
Correct |
121 ms |
79352 KB |
Output is correct |
7 |
Correct |
112 ms |
79352 KB |
Output is correct |
8 |
Correct |
141 ms |
79352 KB |
Output is correct |
9 |
Correct |
303 ms |
79384 KB |
Output is correct |
10 |
Correct |
406 ms |
79384 KB |
Output is correct |
11 |
Correct |
406 ms |
79384 KB |
Output is correct |
12 |
Correct |
195 ms |
79384 KB |
Output is correct |
13 |
Correct |
112 ms |
79384 KB |
Output is correct |
14 |
Correct |
146 ms |
79384 KB |
Output is correct |
15 |
Correct |
305 ms |
79384 KB |
Output is correct |
16 |
Correct |
155 ms |
79428 KB |
Output is correct |
17 |
Correct |
338 ms |
79428 KB |
Output is correct |
18 |
Correct |
345 ms |
79428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
79436 KB |
Output is correct |
2 |
Correct |
383 ms |
79436 KB |
Output is correct |
3 |
Correct |
405 ms |
79516 KB |
Output is correct |
4 |
Correct |
219 ms |
79516 KB |
Output is correct |
5 |
Correct |
234 ms |
79840 KB |
Output is correct |
6 |
Correct |
330 ms |
79840 KB |
Output is correct |
7 |
Correct |
293 ms |
79852 KB |
Output is correct |
8 |
Correct |
307 ms |
79852 KB |
Output is correct |
9 |
Correct |
334 ms |
79852 KB |
Output is correct |
10 |
Correct |
256 ms |
79852 KB |
Output is correct |
11 |
Correct |
225 ms |
79852 KB |
Output is correct |
12 |
Correct |
292 ms |
79852 KB |
Output is correct |
13 |
Correct |
380 ms |
79852 KB |
Output is correct |
14 |
Correct |
256 ms |
79928 KB |
Output is correct |
15 |
Correct |
317 ms |
79928 KB |
Output is correct |
16 |
Correct |
340 ms |
79928 KB |
Output is correct |
17 |
Correct |
334 ms |
79928 KB |
Output is correct |
18 |
Correct |
383 ms |
79928 KB |
Output is correct |
19 |
Correct |
126 ms |
79928 KB |
Output is correct |
20 |
Correct |
394 ms |
79928 KB |
Output is correct |
21 |
Correct |
232 ms |
79960 KB |
Output is correct |
22 |
Correct |
414 ms |
80024 KB |
Output is correct |
23 |
Correct |
183 ms |
80024 KB |
Output is correct |
24 |
Correct |
166 ms |
80024 KB |
Output is correct |
25 |
Correct |
269 ms |
80024 KB |
Output is correct |
26 |
Correct |
224 ms |
80024 KB |
Output is correct |
27 |
Correct |
419 ms |
80024 KB |
Output is correct |
28 |
Correct |
138 ms |
80024 KB |
Output is correct |
29 |
Correct |
408 ms |
80024 KB |
Output is correct |
30 |
Correct |
394 ms |
80024 KB |
Output is correct |
31 |
Correct |
192 ms |
80024 KB |
Output is correct |
32 |
Correct |
203 ms |
80024 KB |
Output is correct |
33 |
Correct |
126 ms |
80024 KB |
Output is correct |
34 |
Correct |
311 ms |
80024 KB |
Output is correct |
35 |
Correct |
169 ms |
80024 KB |
Output is correct |
36 |
Correct |
379 ms |
80024 KB |
Output is correct |
37 |
Correct |
205 ms |
80024 KB |
Output is correct |
38 |
Correct |
325 ms |
80024 KB |
Output is correct |
39 |
Correct |
149 ms |
80024 KB |
Output is correct |
40 |
Correct |
268 ms |
80024 KB |
Output is correct |
41 |
Correct |
246 ms |
80024 KB |
Output is correct |
42 |
Correct |
392 ms |
80024 KB |
Output is correct |