#include <bits/stdc++.h>
const int32_t MAX_N = 2e7;
int32_t dp[MAX_N + 5];
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int32_t m, q;
std::cin >> m >> q;
int64_t lcm = 1;
for(int32_t i = 0; i < m; i++) {
int32_t p;
std::cin >> p;
for(int32_t j = p - 1; j <= MAX_N; j += p) {
dp[j] = p - 1;
}
if(lcm < MAX_N) {
lcm *= (int64_t) p;
}
}
for(int32_t i = MAX_N - 1; i >= 1; i--) {
dp[i] = std::max(dp[i], dp[i + 1] - 1);
}
dp[0] = 0;
for(int32_t i = 1; i <= MAX_N; i++) {
dp[i] = dp[i - dp[i]] + 1;
}
for(int32_t i = 0; i < q; i++) {
int32_t n;
std::cin >> n;
if(n >= lcm) {
std::cout << "oo" << '\n';
}
else {
std::cout << dp[n] << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
187 ms |
78712 KB |
Output is correct |
2 |
Correct |
286 ms |
78856 KB |
Output is correct |
3 |
Correct |
239 ms |
78856 KB |
Output is correct |
4 |
Correct |
194 ms |
78884 KB |
Output is correct |
5 |
Correct |
261 ms |
78884 KB |
Output is correct |
6 |
Correct |
211 ms |
78884 KB |
Output is correct |
7 |
Correct |
211 ms |
78884 KB |
Output is correct |
8 |
Correct |
225 ms |
78884 KB |
Output is correct |
9 |
Correct |
270 ms |
78960 KB |
Output is correct |
10 |
Correct |
318 ms |
78960 KB |
Output is correct |
11 |
Correct |
333 ms |
78960 KB |
Output is correct |
12 |
Correct |
190 ms |
78960 KB |
Output is correct |
13 |
Correct |
644 ms |
78988 KB |
Output is correct |
14 |
Correct |
624 ms |
79032 KB |
Output is correct |
15 |
Correct |
271 ms |
79032 KB |
Output is correct |
16 |
Correct |
238 ms |
79032 KB |
Output is correct |
17 |
Correct |
263 ms |
79100 KB |
Output is correct |
18 |
Correct |
213 ms |
79116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
239 ms |
79116 KB |
Output is correct |
2 |
Correct |
279 ms |
79132 KB |
Output is correct |
3 |
Correct |
835 ms |
79132 KB |
Output is correct |
4 |
Correct |
322 ms |
79132 KB |
Output is correct |
5 |
Correct |
546 ms |
79132 KB |
Output is correct |
6 |
Correct |
261 ms |
79132 KB |
Output is correct |
7 |
Correct |
269 ms |
79132 KB |
Output is correct |
8 |
Correct |
358 ms |
79132 KB |
Output is correct |
9 |
Correct |
767 ms |
79132 KB |
Output is correct |
10 |
Correct |
817 ms |
79132 KB |
Output is correct |
11 |
Correct |
841 ms |
79132 KB |
Output is correct |
12 |
Correct |
499 ms |
79132 KB |
Output is correct |
13 |
Correct |
233 ms |
79136 KB |
Output is correct |
14 |
Correct |
347 ms |
79136 KB |
Output is correct |
15 |
Correct |
706 ms |
79136 KB |
Output is correct |
16 |
Correct |
315 ms |
79136 KB |
Output is correct |
17 |
Correct |
800 ms |
79136 KB |
Output is correct |
18 |
Correct |
653 ms |
79200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
668 ms |
79472 KB |
Output is correct |
2 |
Execution timed out |
1006 ms |
79512 KB |
Time limit exceeded |
3 |
Correct |
976 ms |
79532 KB |
Output is correct |
4 |
Correct |
527 ms |
79600 KB |
Output is correct |
5 |
Correct |
374 ms |
79600 KB |
Output is correct |
6 |
Correct |
753 ms |
79600 KB |
Output is correct |
7 |
Correct |
670 ms |
79600 KB |
Output is correct |
8 |
Correct |
685 ms |
79600 KB |
Output is correct |
9 |
Correct |
650 ms |
79600 KB |
Output is correct |
10 |
Correct |
537 ms |
79600 KB |
Output is correct |
11 |
Correct |
465 ms |
79600 KB |
Output is correct |
12 |
Correct |
600 ms |
79600 KB |
Output is correct |
13 |
Correct |
767 ms |
79728 KB |
Output is correct |
14 |
Correct |
432 ms |
79984 KB |
Output is correct |
15 |
Correct |
624 ms |
79984 KB |
Output is correct |
16 |
Correct |
719 ms |
79984 KB |
Output is correct |
17 |
Correct |
671 ms |
79984 KB |
Output is correct |
18 |
Correct |
855 ms |
79984 KB |
Output is correct |
19 |
Correct |
227 ms |
79984 KB |
Output is correct |
20 |
Correct |
950 ms |
79984 KB |
Output is correct |
21 |
Correct |
448 ms |
80052 KB |
Output is correct |
22 |
Correct |
883 ms |
80052 KB |
Output is correct |
23 |
Correct |
385 ms |
80052 KB |
Output is correct |
24 |
Correct |
300 ms |
80052 KB |
Output is correct |
25 |
Correct |
605 ms |
80052 KB |
Output is correct |
26 |
Correct |
462 ms |
80052 KB |
Output is correct |
27 |
Execution timed out |
1020 ms |
80052 KB |
Time limit exceeded |
28 |
Correct |
293 ms |
80052 KB |
Output is correct |
29 |
Correct |
818 ms |
80052 KB |
Output is correct |
30 |
Correct |
766 ms |
80052 KB |
Output is correct |
31 |
Correct |
324 ms |
80052 KB |
Output is correct |
32 |
Correct |
364 ms |
80052 KB |
Output is correct |
33 |
Correct |
233 ms |
80052 KB |
Output is correct |
34 |
Correct |
580 ms |
80052 KB |
Output is correct |
35 |
Correct |
285 ms |
80052 KB |
Output is correct |
36 |
Correct |
783 ms |
80052 KB |
Output is correct |
37 |
Correct |
374 ms |
80052 KB |
Output is correct |
38 |
Correct |
663 ms |
80052 KB |
Output is correct |
39 |
Correct |
293 ms |
80052 KB |
Output is correct |
40 |
Correct |
562 ms |
80052 KB |
Output is correct |
41 |
Correct |
554 ms |
80052 KB |
Output is correct |
42 |
Correct |
843 ms |
80052 KB |
Output is correct |