#include <iostream>
#include <string.h>
using namespace std;
const int N = 1e5+5, MAXN = 1e7+7, INF = 1e9+9;
int n, q, x, p[N], dp[MAXN], mx[MAXN];
int main()
{
cin >> n >> q;
for (int i = 0; i < n; i++)
{
cin >> p[i];
for (int j = p[i]-1; j < MAXN; j += p[i])
{
mx[j] = max(mx[j], p[i]-1);
}
}
for (int i = MAXN - 2; i >= 0; i--)
mx[i] = max(mx[i], mx[i+1]-1);
for (int i = 1; i < MAXN; i++)
{
if (mx[i] > 0)
dp[i] = 1 + dp[i-mx[i]];
else
dp[i] = INF;
}
while(q--)
{
cin >> x;
if (dp[x] == INF) cout << "oo\n";
else cout << dp[x] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
145 ms |
78584 KB |
Output isn't correct |
2 |
Correct |
169 ms |
78584 KB |
Output is correct |
3 |
Correct |
159 ms |
78584 KB |
Output is correct |
4 |
Correct |
172 ms |
78632 KB |
Output is correct |
5 |
Correct |
171 ms |
78608 KB |
Output is correct |
6 |
Incorrect |
139 ms |
78580 KB |
Output isn't correct |
7 |
Correct |
145 ms |
78548 KB |
Output is correct |
8 |
Correct |
153 ms |
78584 KB |
Output is correct |
9 |
Correct |
172 ms |
78560 KB |
Output is correct |
10 |
Correct |
192 ms |
78540 KB |
Output is correct |
11 |
Correct |
183 ms |
78648 KB |
Output is correct |
12 |
Correct |
133 ms |
78564 KB |
Output is correct |
13 |
Correct |
286 ms |
78592 KB |
Output is correct |
14 |
Correct |
318 ms |
78584 KB |
Output is correct |
15 |
Correct |
168 ms |
78712 KB |
Output is correct |
16 |
Correct |
156 ms |
78584 KB |
Output is correct |
17 |
Correct |
187 ms |
78552 KB |
Output is correct |
18 |
Correct |
164 ms |
78672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
78584 KB |
Output is correct |
2 |
Correct |
213 ms |
78952 KB |
Output is correct |
3 |
Correct |
386 ms |
78880 KB |
Output is correct |
4 |
Correct |
172 ms |
78584 KB |
Output is correct |
5 |
Correct |
277 ms |
78792 KB |
Output is correct |
6 |
Correct |
154 ms |
78584 KB |
Output is correct |
7 |
Correct |
179 ms |
78736 KB |
Output is correct |
8 |
Correct |
176 ms |
78676 KB |
Output is correct |
9 |
Correct |
356 ms |
78828 KB |
Output is correct |
10 |
Correct |
437 ms |
78840 KB |
Output is correct |
11 |
Incorrect |
415 ms |
78840 KB |
Output isn't correct |
12 |
Correct |
244 ms |
78584 KB |
Output is correct |
13 |
Correct |
161 ms |
78584 KB |
Output is correct |
14 |
Correct |
174 ms |
78616 KB |
Output is correct |
15 |
Correct |
304 ms |
78844 KB |
Output is correct |
16 |
Correct |
241 ms |
78968 KB |
Output is correct |
17 |
Correct |
292 ms |
78584 KB |
Output is correct |
18 |
Correct |
336 ms |
78968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
456 ms |
78840 KB |
Output is correct |
2 |
Correct |
456 ms |
78976 KB |
Output is correct |
3 |
Correct |
540 ms |
79208 KB |
Output is correct |
4 |
Incorrect |
522 ms |
78912 KB |
Output isn't correct |
5 |
Incorrect |
573 ms |
79352 KB |
Output isn't correct |
6 |
Correct |
681 ms |
79096 KB |
Output is correct |
7 |
Correct |
512 ms |
79204 KB |
Output is correct |
8 |
Correct |
450 ms |
78840 KB |
Output is correct |
9 |
Correct |
488 ms |
78960 KB |
Output is correct |
10 |
Correct |
290 ms |
78860 KB |
Output is correct |
11 |
Incorrect |
291 ms |
78840 KB |
Output isn't correct |
12 |
Correct |
344 ms |
78856 KB |
Output is correct |
13 |
Correct |
647 ms |
79196 KB |
Output is correct |
14 |
Correct |
523 ms |
79192 KB |
Output is correct |
15 |
Incorrect |
374 ms |
78700 KB |
Output isn't correct |
16 |
Correct |
388 ms |
78712 KB |
Output is correct |
17 |
Correct |
347 ms |
78840 KB |
Output is correct |
18 |
Correct |
457 ms |
78932 KB |
Output is correct |
19 |
Incorrect |
228 ms |
78732 KB |
Output isn't correct |
20 |
Correct |
551 ms |
78968 KB |
Output is correct |
21 |
Incorrect |
579 ms |
79268 KB |
Output isn't correct |
22 |
Correct |
785 ms |
79488 KB |
Output is correct |
23 |
Correct |
542 ms |
78936 KB |
Output is correct |
24 |
Correct |
472 ms |
78940 KB |
Output is correct |
25 |
Correct |
602 ms |
79060 KB |
Output is correct |
26 |
Incorrect |
520 ms |
78880 KB |
Output isn't correct |
27 |
Correct |
607 ms |
79096 KB |
Output is correct |
28 |
Incorrect |
477 ms |
78972 KB |
Output isn't correct |
29 |
Correct |
700 ms |
79476 KB |
Output is correct |
30 |
Correct |
664 ms |
79224 KB |
Output is correct |
31 |
Correct |
456 ms |
78968 KB |
Output is correct |
32 |
Incorrect |
496 ms |
78940 KB |
Output isn't correct |
33 |
Incorrect |
438 ms |
78716 KB |
Output isn't correct |
34 |
Correct |
491 ms |
79172 KB |
Output is correct |
35 |
Incorrect |
491 ms |
79096 KB |
Output isn't correct |
36 |
Correct |
801 ms |
79196 KB |
Output is correct |
37 |
Incorrect |
576 ms |
79504 KB |
Output isn't correct |
38 |
Correct |
655 ms |
78896 KB |
Output is correct |
39 |
Incorrect |
657 ms |
79148 KB |
Output isn't correct |
40 |
Correct |
597 ms |
78972 KB |
Output is correct |
41 |
Correct |
463 ms |
79196 KB |
Output is correct |
42 |
Correct |
659 ms |
79112 KB |
Output is correct |