#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 5;
vector<int> dp(maxn, 1e9), L(maxn, 1e9);
int main() {
int n, q;
cin >> n >> q;
vector<int> p(n);
for(int &x : p) cin >> x;
L[0] = 0; dp[0] = 0;
for(int &x : p)
for(int i=0; i*x<1e7; i++) L[min((int)1e7, (i+1)*x-1)] = min(L[min((int)1e7, (i+1)*x-1)] , i * x);
for(int i=1e7-1; i>=1; i--) L[i] = min(L[i], L[i+1]);
for(int i=1; i<=1e7; i++) {
if(L[i] >= i) dp[i] = 1e9;
else dp[i] = dp[L[i]] + 1;
}
while(q--) {
int x;
cin >> x;
if(dp[x] < 1e9) cout << dp[x] << '\n';
else cout << "oo\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
78680 KB |
Output is correct |
2 |
Correct |
64 ms |
78684 KB |
Output is correct |
3 |
Correct |
66 ms |
78680 KB |
Output is correct |
4 |
Correct |
64 ms |
78732 KB |
Output is correct |
5 |
Correct |
60 ms |
78684 KB |
Output is correct |
6 |
Correct |
55 ms |
78684 KB |
Output is correct |
7 |
Correct |
64 ms |
78684 KB |
Output is correct |
8 |
Correct |
66 ms |
78684 KB |
Output is correct |
9 |
Correct |
80 ms |
78684 KB |
Output is correct |
10 |
Correct |
106 ms |
78684 KB |
Output is correct |
11 |
Correct |
81 ms |
78540 KB |
Output is correct |
12 |
Correct |
49 ms |
78680 KB |
Output is correct |
13 |
Correct |
134 ms |
78680 KB |
Output is correct |
14 |
Correct |
131 ms |
78768 KB |
Output is correct |
15 |
Correct |
72 ms |
78680 KB |
Output is correct |
16 |
Correct |
73 ms |
78684 KB |
Output is correct |
17 |
Correct |
78 ms |
78732 KB |
Output is correct |
18 |
Correct |
70 ms |
78680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
78684 KB |
Output is correct |
2 |
Correct |
81 ms |
79520 KB |
Output is correct |
3 |
Correct |
162 ms |
79452 KB |
Output is correct |
4 |
Correct |
67 ms |
78712 KB |
Output is correct |
5 |
Correct |
117 ms |
78912 KB |
Output is correct |
6 |
Correct |
65 ms |
78684 KB |
Output is correct |
7 |
Correct |
61 ms |
78684 KB |
Output is correct |
8 |
Correct |
72 ms |
78700 KB |
Output is correct |
9 |
Correct |
128 ms |
78936 KB |
Output is correct |
10 |
Correct |
173 ms |
78940 KB |
Output is correct |
11 |
Correct |
143 ms |
78684 KB |
Output is correct |
12 |
Correct |
85 ms |
78680 KB |
Output is correct |
13 |
Correct |
60 ms |
78684 KB |
Output is correct |
14 |
Correct |
71 ms |
78680 KB |
Output is correct |
15 |
Correct |
155 ms |
78684 KB |
Output is correct |
16 |
Correct |
90 ms |
78940 KB |
Output is correct |
17 |
Correct |
127 ms |
78684 KB |
Output is correct |
18 |
Correct |
137 ms |
79100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
78932 KB |
Output is correct |
2 |
Correct |
191 ms |
78924 KB |
Output is correct |
3 |
Correct |
229 ms |
78932 KB |
Output is correct |
4 |
Correct |
199 ms |
78728 KB |
Output is correct |
5 |
Correct |
207 ms |
79188 KB |
Output is correct |
6 |
Correct |
257 ms |
78928 KB |
Output is correct |
7 |
Correct |
186 ms |
79188 KB |
Output is correct |
8 |
Correct |
175 ms |
79168 KB |
Output is correct |
9 |
Correct |
180 ms |
78936 KB |
Output is correct |
10 |
Correct |
113 ms |
78720 KB |
Output is correct |
11 |
Correct |
115 ms |
78684 KB |
Output is correct |
12 |
Correct |
139 ms |
78680 KB |
Output is correct |
13 |
Correct |
254 ms |
78932 KB |
Output is correct |
14 |
Correct |
207 ms |
79216 KB |
Output is correct |
15 |
Correct |
153 ms |
78932 KB |
Output is correct |
16 |
Correct |
174 ms |
78732 KB |
Output is correct |
17 |
Correct |
142 ms |
78684 KB |
Output is correct |
18 |
Correct |
206 ms |
78936 KB |
Output is correct |
19 |
Correct |
94 ms |
78876 KB |
Output is correct |
20 |
Correct |
224 ms |
78932 KB |
Output is correct |
21 |
Correct |
225 ms |
79184 KB |
Output is correct |
22 |
Correct |
293 ms |
79096 KB |
Output is correct |
23 |
Correct |
196 ms |
78828 KB |
Output is correct |
24 |
Correct |
177 ms |
78884 KB |
Output is correct |
25 |
Correct |
219 ms |
78932 KB |
Output is correct |
26 |
Correct |
207 ms |
78928 KB |
Output is correct |
27 |
Correct |
256 ms |
79188 KB |
Output is correct |
28 |
Correct |
191 ms |
78932 KB |
Output is correct |
29 |
Correct |
266 ms |
79188 KB |
Output is correct |
30 |
Correct |
260 ms |
78976 KB |
Output is correct |
31 |
Correct |
181 ms |
78720 KB |
Output is correct |
32 |
Correct |
194 ms |
78928 KB |
Output is correct |
33 |
Correct |
176 ms |
78732 KB |
Output is correct |
34 |
Correct |
187 ms |
79088 KB |
Output is correct |
35 |
Correct |
193 ms |
78928 KB |
Output is correct |
36 |
Correct |
293 ms |
79188 KB |
Output is correct |
37 |
Correct |
211 ms |
79188 KB |
Output is correct |
38 |
Correct |
254 ms |
78992 KB |
Output is correct |
39 |
Correct |
191 ms |
78932 KB |
Output is correct |
40 |
Correct |
225 ms |
78932 KB |
Output is correct |
41 |
Correct |
198 ms |
79192 KB |
Output is correct |
42 |
Correct |
271 ms |
78928 KB |
Output is correct |