#include <bits/stdc++.h>
using namespace std;
const int mxn = 10 * 1000 * 1000 + 200 * 1000;
const int inf = 2e9;
int dp[mxn], sub[mxn];
int m, q;
signed main() {
std::ios::sync_with_stdio(0);
std::cout.tie(0);
std::cin.tie(0);
#ifdef saarang
freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
#endif
cin >> m >> q;
memset(dp, 0x7f, sizeof dp);
vector<int> p(m);
for(int i = 0; i < m; i++)
cin >> p[i];
sort(p.begin(), p.end());
dp[0] = 0;
for(int i = 1; i < p.back(); i++)
dp[i] = 1;
for(int i = 0; i < m; i++)
for(int j = p[i] - 1; j < mxn; j += p[i])
sub[j] = max(sub[j], p[i] - 1);
for(int i = mxn - 2; i >= 0; i--)
sub[i] = max(sub[i], sub[i + 1] - 1);
for(int i = p.back(); i < mxn; i++)
dp[i] = min(dp[i], dp[i - sub[i]] + 1);
while(q--) {
int n; cin >> n;
if(dp[n] >= inf) cout << "oo\n";
else cout << dp[n] << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
80068 KB |
Output is correct |
2 |
Correct |
141 ms |
80068 KB |
Output is correct |
3 |
Correct |
123 ms |
80068 KB |
Output is correct |
4 |
Correct |
112 ms |
80116 KB |
Output is correct |
5 |
Correct |
127 ms |
80140 KB |
Output is correct |
6 |
Correct |
112 ms |
80148 KB |
Output is correct |
7 |
Correct |
123 ms |
80196 KB |
Output is correct |
8 |
Correct |
128 ms |
80196 KB |
Output is correct |
9 |
Correct |
145 ms |
80068 KB |
Output is correct |
10 |
Correct |
170 ms |
80196 KB |
Output is correct |
11 |
Correct |
161 ms |
80068 KB |
Output is correct |
12 |
Correct |
112 ms |
80048 KB |
Output is correct |
13 |
Correct |
278 ms |
80064 KB |
Output is correct |
14 |
Correct |
314 ms |
80160 KB |
Output is correct |
15 |
Correct |
153 ms |
80100 KB |
Output is correct |
16 |
Correct |
138 ms |
80144 KB |
Output is correct |
17 |
Correct |
138 ms |
80152 KB |
Output is correct |
18 |
Correct |
111 ms |
80196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
80196 KB |
Output is correct |
2 |
Correct |
146 ms |
81208 KB |
Output is correct |
3 |
Correct |
345 ms |
80896 KB |
Output is correct |
4 |
Correct |
154 ms |
80172 KB |
Output is correct |
5 |
Correct |
246 ms |
80632 KB |
Output is correct |
6 |
Correct |
135 ms |
80048 KB |
Output is correct |
7 |
Correct |
132 ms |
80196 KB |
Output is correct |
8 |
Correct |
153 ms |
80128 KB |
Output is correct |
9 |
Correct |
283 ms |
80836 KB |
Output is correct |
10 |
Correct |
358 ms |
80872 KB |
Output is correct |
11 |
Correct |
327 ms |
80576 KB |
Output is correct |
12 |
Correct |
196 ms |
80144 KB |
Output is correct |
13 |
Correct |
122 ms |
80132 KB |
Output is correct |
14 |
Correct |
154 ms |
80168 KB |
Output is correct |
15 |
Correct |
289 ms |
80504 KB |
Output is correct |
16 |
Correct |
136 ms |
81208 KB |
Output is correct |
17 |
Correct |
279 ms |
80128 KB |
Output is correct |
18 |
Correct |
282 ms |
81220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
292 ms |
81080 KB |
Output is correct |
2 |
Correct |
360 ms |
81008 KB |
Output is correct |
3 |
Correct |
354 ms |
81232 KB |
Output is correct |
4 |
Correct |
242 ms |
81092 KB |
Output is correct |
5 |
Correct |
173 ms |
82196 KB |
Output is correct |
6 |
Correct |
295 ms |
81092 KB |
Output is correct |
7 |
Correct |
264 ms |
81848 KB |
Output is correct |
8 |
Correct |
279 ms |
81000 KB |
Output is correct |
9 |
Correct |
284 ms |
80976 KB |
Output is correct |
10 |
Correct |
232 ms |
80276 KB |
Output is correct |
11 |
Correct |
200 ms |
80392 KB |
Output is correct |
12 |
Correct |
262 ms |
80324 KB |
Output is correct |
13 |
Correct |
332 ms |
81340 KB |
Output is correct |
14 |
Correct |
199 ms |
81444 KB |
Output is correct |
15 |
Correct |
280 ms |
80452 KB |
Output is correct |
16 |
Correct |
299 ms |
80408 KB |
Output is correct |
17 |
Correct |
268 ms |
80720 KB |
Output is correct |
18 |
Correct |
344 ms |
80900 KB |
Output is correct |
19 |
Correct |
131 ms |
80312 KB |
Output is correct |
20 |
Correct |
359 ms |
81156 KB |
Output is correct |
21 |
Correct |
232 ms |
81472 KB |
Output is correct |
22 |
Correct |
365 ms |
82224 KB |
Output is correct |
23 |
Correct |
185 ms |
81476 KB |
Output is correct |
24 |
Correct |
152 ms |
81080 KB |
Output is correct |
25 |
Correct |
247 ms |
81160 KB |
Output is correct |
26 |
Correct |
223 ms |
81100 KB |
Output is correct |
27 |
Correct |
402 ms |
81684 KB |
Output is correct |
28 |
Correct |
148 ms |
81224 KB |
Output is correct |
29 |
Correct |
342 ms |
82204 KB |
Output is correct |
30 |
Correct |
323 ms |
81984 KB |
Output is correct |
31 |
Correct |
170 ms |
81044 KB |
Output is correct |
32 |
Correct |
187 ms |
81092 KB |
Output is correct |
33 |
Correct |
141 ms |
81056 KB |
Output is correct |
34 |
Correct |
280 ms |
81732 KB |
Output is correct |
35 |
Correct |
157 ms |
81228 KB |
Output is correct |
36 |
Correct |
355 ms |
82096 KB |
Output is correct |
37 |
Correct |
174 ms |
82244 KB |
Output is correct |
38 |
Correct |
297 ms |
81308 KB |
Output is correct |
39 |
Correct |
163 ms |
81140 KB |
Output is correct |
40 |
Correct |
249 ms |
81168 KB |
Output is correct |
41 |
Correct |
223 ms |
81860 KB |
Output is correct |
42 |
Correct |
314 ms |
81356 KB |
Output is correct |