#include <bits/stdc++.h>
using namespace std;
const int nx=1e7+5;
int dp[nx], n, m, x, q, p, res[nx], t, cnt;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>m>>q;
for (int i=0; i<m; i++)
{
cin>>x;
for (int j=x; j<nx; j+=x) dp[j]=x;
}
for (int i=x; i<nx; i++) res[i]=-1;
for (int i=0; i<x; i++) res[i]=1;
t=1;
while (p<nx)
{
int mx=x;
t++;
for (int i=p; i<min(nx-1, x); i++) mx=max(mx, i+dp[i]);
for (int i=x; i<min(nx-1, mx); i++) res[i]=t;
if (mx==x) break;
p=x;
x=mx;
}
//for (int i=0; i<35; i++) cout<<i<<' '<<res[i]<<'\n';
while (q--)
{
cin>>x;
if (res[x]==-1) cout<<"oo\n";
else cout<<res[x]<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
78744 KB |
Output is correct |
2 |
Correct |
37 ms |
78676 KB |
Output is correct |
3 |
Correct |
20 ms |
78684 KB |
Output is correct |
4 |
Correct |
37 ms |
78720 KB |
Output is correct |
5 |
Correct |
35 ms |
78676 KB |
Output is correct |
6 |
Correct |
16 ms |
78688 KB |
Output is correct |
7 |
Correct |
20 ms |
78684 KB |
Output is correct |
8 |
Correct |
22 ms |
78684 KB |
Output is correct |
9 |
Correct |
46 ms |
78732 KB |
Output is correct |
10 |
Correct |
56 ms |
78676 KB |
Output is correct |
11 |
Correct |
58 ms |
78684 KB |
Output is correct |
12 |
Correct |
26 ms |
78684 KB |
Output is correct |
13 |
Correct |
91 ms |
78716 KB |
Output is correct |
14 |
Correct |
91 ms |
78740 KB |
Output is correct |
15 |
Correct |
41 ms |
78684 KB |
Output is correct |
16 |
Correct |
35 ms |
78680 KB |
Output is correct |
17 |
Correct |
36 ms |
78684 KB |
Output is correct |
18 |
Correct |
27 ms |
78728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
78676 KB |
Output is correct |
2 |
Correct |
75 ms |
78728 KB |
Output is correct |
3 |
Correct |
125 ms |
78716 KB |
Output is correct |
4 |
Correct |
41 ms |
78680 KB |
Output is correct |
5 |
Correct |
76 ms |
78680 KB |
Output is correct |
6 |
Correct |
38 ms |
78684 KB |
Output is correct |
7 |
Correct |
32 ms |
78684 KB |
Output is correct |
8 |
Correct |
41 ms |
78680 KB |
Output is correct |
9 |
Correct |
90 ms |
78744 KB |
Output is correct |
10 |
Correct |
115 ms |
78740 KB |
Output is correct |
11 |
Correct |
141 ms |
78680 KB |
Output is correct |
12 |
Correct |
68 ms |
78716 KB |
Output is correct |
13 |
Correct |
38 ms |
78724 KB |
Output is correct |
14 |
Correct |
48 ms |
78716 KB |
Output is correct |
15 |
Correct |
90 ms |
78680 KB |
Output is correct |
16 |
Correct |
45 ms |
78680 KB |
Output is correct |
17 |
Correct |
93 ms |
78712 KB |
Output is correct |
18 |
Correct |
99 ms |
78684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
78740 KB |
Output is correct |
2 |
Correct |
120 ms |
78664 KB |
Output is correct |
3 |
Correct |
115 ms |
78992 KB |
Output is correct |
4 |
Correct |
88 ms |
78940 KB |
Output is correct |
5 |
Correct |
58 ms |
79500 KB |
Output is correct |
6 |
Correct |
104 ms |
79480 KB |
Output is correct |
7 |
Correct |
103 ms |
79188 KB |
Output is correct |
8 |
Correct |
129 ms |
78728 KB |
Output is correct |
9 |
Correct |
103 ms |
78940 KB |
Output is correct |
10 |
Correct |
91 ms |
78676 KB |
Output is correct |
11 |
Correct |
79 ms |
78708 KB |
Output is correct |
12 |
Correct |
88 ms |
78716 KB |
Output is correct |
13 |
Correct |
115 ms |
79444 KB |
Output is correct |
14 |
Correct |
71 ms |
79228 KB |
Output is correct |
15 |
Correct |
103 ms |
78716 KB |
Output is correct |
16 |
Correct |
99 ms |
78680 KB |
Output is correct |
17 |
Correct |
95 ms |
78736 KB |
Output is correct |
18 |
Correct |
127 ms |
78676 KB |
Output is correct |
19 |
Correct |
40 ms |
78684 KB |
Output is correct |
20 |
Correct |
122 ms |
79000 KB |
Output is correct |
21 |
Correct |
84 ms |
79236 KB |
Output is correct |
22 |
Correct |
144 ms |
79440 KB |
Output is correct |
23 |
Correct |
62 ms |
79496 KB |
Output is correct |
24 |
Correct |
50 ms |
79500 KB |
Output is correct |
25 |
Correct |
85 ms |
79484 KB |
Output is correct |
26 |
Correct |
80 ms |
78928 KB |
Output is correct |
27 |
Correct |
135 ms |
78988 KB |
Output is correct |
28 |
Correct |
46 ms |
79708 KB |
Output is correct |
29 |
Correct |
121 ms |
79504 KB |
Output is correct |
30 |
Correct |
114 ms |
79480 KB |
Output is correct |
31 |
Correct |
58 ms |
79440 KB |
Output is correct |
32 |
Correct |
66 ms |
79376 KB |
Output is correct |
33 |
Correct |
50 ms |
79596 KB |
Output is correct |
34 |
Correct |
88 ms |
78968 KB |
Output is correct |
35 |
Correct |
54 ms |
79700 KB |
Output is correct |
36 |
Correct |
125 ms |
79588 KB |
Output is correct |
37 |
Correct |
59 ms |
79500 KB |
Output is correct |
38 |
Correct |
106 ms |
79388 KB |
Output is correct |
39 |
Correct |
71 ms |
79700 KB |
Output is correct |
40 |
Correct |
90 ms |
79440 KB |
Output is correct |
41 |
Correct |
86 ms |
78936 KB |
Output is correct |
42 |
Correct |
116 ms |
79752 KB |
Output is correct |