#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int V = 1e7;
int nxt[V + 7], dp[V + 7];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
for (int j = x; j - 1 <= V; j += x) {
nxt[j - 1] = x - 1;
}
nxt[V] = max(nxt[V], V % x);
}
for (int i = V; i >= 1; --i) {
nxt[i] = max(nxt[i], nxt[i + 1] - 1);
}
for (int i = 1; i <= V; ++i) {
if (nxt[i] == 0 || dp[i - nxt[i]] == -1) {
dp[i] = -1;
} else {
dp[i] = dp[i - nxt[i]] + 1;
}
}
while (q--) {
ll x;
cin >> x;
if (dp[x] < 0) {
cout << "oo\n";
} else {
cout << dp[x] << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
78684 KB |
Output is correct |
2 |
Correct |
35 ms |
78476 KB |
Output is correct |
3 |
Correct |
34 ms |
78744 KB |
Output is correct |
4 |
Correct |
30 ms |
78748 KB |
Output is correct |
5 |
Correct |
33 ms |
78672 KB |
Output is correct |
6 |
Correct |
31 ms |
78672 KB |
Output is correct |
7 |
Correct |
43 ms |
78676 KB |
Output is correct |
8 |
Correct |
37 ms |
78672 KB |
Output is correct |
9 |
Correct |
41 ms |
78676 KB |
Output is correct |
10 |
Correct |
44 ms |
78724 KB |
Output is correct |
11 |
Correct |
44 ms |
78684 KB |
Output is correct |
12 |
Correct |
31 ms |
78672 KB |
Output is correct |
13 |
Correct |
61 ms |
78488 KB |
Output is correct |
14 |
Correct |
61 ms |
78732 KB |
Output is correct |
15 |
Correct |
39 ms |
78676 KB |
Output is correct |
16 |
Correct |
37 ms |
78696 KB |
Output is correct |
17 |
Correct |
35 ms |
78684 KB |
Output is correct |
18 |
Correct |
34 ms |
78752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
78928 KB |
Output is correct |
2 |
Correct |
42 ms |
79188 KB |
Output is correct |
3 |
Correct |
76 ms |
78952 KB |
Output is correct |
4 |
Correct |
38 ms |
78496 KB |
Output is correct |
5 |
Correct |
64 ms |
79044 KB |
Output is correct |
6 |
Correct |
41 ms |
78672 KB |
Output is correct |
7 |
Correct |
35 ms |
78800 KB |
Output is correct |
8 |
Correct |
37 ms |
78696 KB |
Output is correct |
9 |
Correct |
66 ms |
79188 KB |
Output is correct |
10 |
Correct |
82 ms |
79200 KB |
Output is correct |
11 |
Correct |
72 ms |
78928 KB |
Output is correct |
12 |
Correct |
58 ms |
78696 KB |
Output is correct |
13 |
Correct |
33 ms |
78704 KB |
Output is correct |
14 |
Correct |
38 ms |
78672 KB |
Output is correct |
15 |
Correct |
66 ms |
79000 KB |
Output is correct |
16 |
Correct |
43 ms |
79184 KB |
Output is correct |
17 |
Correct |
73 ms |
78676 KB |
Output is correct |
18 |
Correct |
71 ms |
79216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
79288 KB |
Output is correct |
2 |
Correct |
87 ms |
79184 KB |
Output is correct |
3 |
Correct |
79 ms |
79408 KB |
Output is correct |
4 |
Correct |
61 ms |
79440 KB |
Output is correct |
5 |
Correct |
55 ms |
80208 KB |
Output is correct |
6 |
Correct |
70 ms |
79636 KB |
Output is correct |
7 |
Correct |
76 ms |
79956 KB |
Output is correct |
8 |
Correct |
71 ms |
79444 KB |
Output is correct |
9 |
Correct |
72 ms |
79444 KB |
Output is correct |
10 |
Correct |
51 ms |
78840 KB |
Output is correct |
11 |
Correct |
49 ms |
78932 KB |
Output is correct |
12 |
Correct |
61 ms |
78932 KB |
Output is correct |
13 |
Correct |
76 ms |
79776 KB |
Output is correct |
14 |
Correct |
54 ms |
79996 KB |
Output is correct |
15 |
Correct |
62 ms |
79008 KB |
Output is correct |
16 |
Correct |
66 ms |
78928 KB |
Output is correct |
17 |
Correct |
65 ms |
78932 KB |
Output is correct |
18 |
Correct |
85 ms |
79184 KB |
Output is correct |
19 |
Correct |
37 ms |
78768 KB |
Output is correct |
20 |
Correct |
82 ms |
79444 KB |
Output is correct |
21 |
Correct |
85 ms |
79952 KB |
Output is correct |
22 |
Correct |
101 ms |
80208 KB |
Output is correct |
23 |
Correct |
49 ms |
79700 KB |
Output is correct |
24 |
Correct |
50 ms |
79588 KB |
Output is correct |
25 |
Correct |
83 ms |
79696 KB |
Output is correct |
26 |
Correct |
79 ms |
79508 KB |
Output is correct |
27 |
Correct |
104 ms |
79752 KB |
Output is correct |
28 |
Correct |
58 ms |
79772 KB |
Output is correct |
29 |
Correct |
91 ms |
80212 KB |
Output is correct |
30 |
Correct |
98 ms |
79952 KB |
Output is correct |
31 |
Correct |
53 ms |
79620 KB |
Output is correct |
32 |
Correct |
50 ms |
79696 KB |
Output is correct |
33 |
Correct |
44 ms |
79512 KB |
Output is correct |
34 |
Correct |
73 ms |
79956 KB |
Output is correct |
35 |
Correct |
45 ms |
79696 KB |
Output is correct |
36 |
Correct |
121 ms |
80232 KB |
Output is correct |
37 |
Correct |
60 ms |
80212 KB |
Output is correct |
38 |
Correct |
77 ms |
79700 KB |
Output is correct |
39 |
Correct |
49 ms |
79700 KB |
Output is correct |
40 |
Correct |
64 ms |
79512 KB |
Output is correct |
41 |
Correct |
62 ms |
79956 KB |
Output is correct |
42 |
Correct |
76 ms |
79900 KB |
Output is correct |