#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 < N; j+= p[i]) pr[j] = p[i];
}
pr[0] = p[n];
dp[0] = 1;
for(int i = 0; i < N; i++)
{
if(!dp[i]) continue;
for(int j = lim + 1; j < min(N, i + pr[i]); j++) dp[j] = dp[i] + 1;
lim = max(lim, min(N, 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 |
3 ms |
760 KB |
Output is correct |
2 |
Correct |
3 ms |
1124 KB |
Output is correct |
3 |
Correct |
3 ms |
1200 KB |
Output is correct |
4 |
Correct |
5 ms |
1216 KB |
Output is correct |
5 |
Correct |
4 ms |
1216 KB |
Output is correct |
6 |
Correct |
3 ms |
1216 KB |
Output is correct |
7 |
Correct |
3 ms |
1308 KB |
Output is correct |
8 |
Correct |
3 ms |
1312 KB |
Output is correct |
9 |
Correct |
4 ms |
1312 KB |
Output is correct |
10 |
Correct |
5 ms |
1388 KB |
Output is correct |
11 |
Correct |
5 ms |
1388 KB |
Output is correct |
12 |
Correct |
3 ms |
1388 KB |
Output is correct |
13 |
Correct |
5 ms |
1476 KB |
Output is correct |
14 |
Correct |
7 ms |
1476 KB |
Output is correct |
15 |
Correct |
4 ms |
1476 KB |
Output is correct |
16 |
Correct |
3 ms |
1496 KB |
Output is correct |
17 |
Correct |
8 ms |
1496 KB |
Output is correct |
18 |
Correct |
5 ms |
1496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1496 KB |
Output isn't correct |
2 |
Incorrect |
15 ms |
1804 KB |
Output isn't correct |
3 |
Incorrect |
16 ms |
1804 KB |
Output isn't correct |
4 |
Incorrect |
3 ms |
1804 KB |
Output isn't correct |
5 |
Incorrect |
9 ms |
1804 KB |
Output isn't correct |
6 |
Incorrect |
3 ms |
1804 KB |
Output isn't correct |
7 |
Incorrect |
4 ms |
1804 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
1804 KB |
Output isn't correct |
9 |
Incorrect |
11 ms |
1804 KB |
Output isn't correct |
10 |
Incorrect |
11 ms |
1804 KB |
Output isn't correct |
11 |
Incorrect |
7 ms |
1804 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
1804 KB |
Output isn't correct |
13 |
Incorrect |
4 ms |
1804 KB |
Output isn't correct |
14 |
Incorrect |
3 ms |
1804 KB |
Output isn't correct |
15 |
Incorrect |
8 ms |
1804 KB |
Output isn't correct |
16 |
Incorrect |
13 ms |
1900 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
1900 KB |
Output isn't correct |
18 |
Incorrect |
16 ms |
1900 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
2028 KB |
Output isn't correct |
2 |
Incorrect |
22 ms |
2188 KB |
Output isn't correct |
3 |
Incorrect |
19 ms |
2460 KB |
Output isn't correct |
4 |
Incorrect |
35 ms |
2460 KB |
Output isn't correct |
5 |
Incorrect |
62 ms |
3072 KB |
Output isn't correct |
6 |
Incorrect |
28 ms |
3072 KB |
Output isn't correct |
7 |
Incorrect |
30 ms |
3072 KB |
Output isn't correct |
8 |
Incorrect |
20 ms |
3080 KB |
Output isn't correct |
9 |
Incorrect |
23 ms |
3324 KB |
Output isn't correct |
10 |
Incorrect |
13 ms |
3324 KB |
Output isn't correct |
11 |
Incorrect |
20 ms |
3324 KB |
Output isn't correct |
12 |
Incorrect |
16 ms |
3324 KB |
Output isn't correct |
13 |
Incorrect |
22 ms |
3472 KB |
Output isn't correct |
14 |
Incorrect |
20 ms |
3472 KB |
Output isn't correct |
15 |
Incorrect |
17 ms |
3472 KB |
Output isn't correct |
16 |
Incorrect |
20 ms |
3472 KB |
Output isn't correct |
17 |
Incorrect |
17 ms |
3472 KB |
Output isn't correct |
18 |
Incorrect |
25 ms |
3472 KB |
Output isn't correct |
19 |
Incorrect |
18 ms |
3472 KB |
Output isn't correct |
20 |
Incorrect |
20 ms |
3528 KB |
Output isn't correct |
21 |
Incorrect |
21 ms |
3528 KB |
Output isn't correct |
22 |
Incorrect |
37 ms |
3732 KB |
Output isn't correct |
23 |
Incorrect |
26 ms |
3732 KB |
Output isn't correct |
24 |
Incorrect |
29 ms |
3732 KB |
Output isn't correct |
25 |
Incorrect |
33 ms |
3732 KB |
Output isn't correct |
26 |
Incorrect |
32 ms |
3732 KB |
Output isn't correct |
27 |
Incorrect |
28 ms |
3732 KB |
Output isn't correct |
28 |
Incorrect |
19 ms |
3732 KB |
Output isn't correct |
29 |
Incorrect |
35 ms |
3888 KB |
Output isn't correct |
30 |
Incorrect |
32 ms |
3888 KB |
Output isn't correct |
31 |
Incorrect |
31 ms |
3888 KB |
Output isn't correct |
32 |
Incorrect |
29 ms |
3888 KB |
Output isn't correct |
33 |
Incorrect |
29 ms |
3888 KB |
Output isn't correct |
34 |
Incorrect |
26 ms |
3888 KB |
Output isn't correct |
35 |
Incorrect |
23 ms |
3888 KB |
Output isn't correct |
36 |
Incorrect |
46 ms |
3888 KB |
Output isn't correct |
37 |
Incorrect |
35 ms |
3888 KB |
Output isn't correct |
38 |
Incorrect |
31 ms |
3888 KB |
Output isn't correct |
39 |
Incorrect |
32 ms |
3888 KB |
Output isn't correct |
40 |
Incorrect |
30 ms |
3888 KB |
Output isn't correct |
41 |
Incorrect |
26 ms |
3888 KB |
Output isn't correct |
42 |
Incorrect |
22 ms |
3888 KB |
Output isn't correct |