#include "bits/stdc++.h"
using namespace std;
const int N = (int) 1e7 + 22, inf = (int) 1e9;
int dp[N], mx[N];
void solve() {
fill(dp, dp + N, inf);
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = a[i]; j < N; j += a[i]) {
mx[j - 1] = max(mx[j - 1], a[i] - 1);
}
mx[N - 1] = max(mx[N - 1], (N - 1) % a[i]);
}
for (int i = N - 1; i > 0; i--) {
mx[i] = max(mx[i], mx[i + 1] - 1);
}
dp[0] = 0;
for (int i = 1; i < N; i++) {
if (!mx[i]) {
continue;
}
dp[i] = min(inf, dp[i - mx[i]] + 1);
}
while (q--) {
int x;
cin >> x;
if (dp[x] == inf) {
cout << "oo\n";
} else {
cout << dp[x] << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
78672 KB |
Output is correct |
2 |
Correct |
91 ms |
78664 KB |
Output is correct |
3 |
Correct |
72 ms |
78664 KB |
Output is correct |
4 |
Correct |
59 ms |
78720 KB |
Output is correct |
5 |
Correct |
64 ms |
78672 KB |
Output is correct |
6 |
Correct |
58 ms |
78664 KB |
Output is correct |
7 |
Correct |
93 ms |
78660 KB |
Output is correct |
8 |
Correct |
94 ms |
78672 KB |
Output is correct |
9 |
Correct |
80 ms |
78680 KB |
Output is correct |
10 |
Correct |
80 ms |
78656 KB |
Output is correct |
11 |
Correct |
101 ms |
78612 KB |
Output is correct |
12 |
Correct |
78 ms |
78596 KB |
Output is correct |
13 |
Correct |
150 ms |
78676 KB |
Output is correct |
14 |
Correct |
118 ms |
78784 KB |
Output is correct |
15 |
Correct |
78 ms |
78664 KB |
Output is correct |
16 |
Correct |
77 ms |
78540 KB |
Output is correct |
17 |
Correct |
69 ms |
78696 KB |
Output is correct |
18 |
Correct |
60 ms |
78752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
78664 KB |
Output is correct |
2 |
Correct |
86 ms |
79660 KB |
Output is correct |
3 |
Correct |
132 ms |
79440 KB |
Output is correct |
4 |
Correct |
81 ms |
78664 KB |
Output is correct |
5 |
Correct |
100 ms |
79256 KB |
Output is correct |
6 |
Correct |
75 ms |
78664 KB |
Output is correct |
7 |
Correct |
85 ms |
78852 KB |
Output is correct |
8 |
Correct |
69 ms |
78664 KB |
Output is correct |
9 |
Correct |
120 ms |
79344 KB |
Output is correct |
10 |
Correct |
168 ms |
79432 KB |
Output is correct |
11 |
Correct |
139 ms |
78920 KB |
Output is correct |
12 |
Correct |
88 ms |
78564 KB |
Output is correct |
13 |
Correct |
63 ms |
78664 KB |
Output is correct |
14 |
Correct |
81 ms |
78668 KB |
Output is correct |
15 |
Correct |
116 ms |
79084 KB |
Output is correct |
16 |
Correct |
84 ms |
79736 KB |
Output is correct |
17 |
Correct |
116 ms |
78612 KB |
Output is correct |
18 |
Correct |
135 ms |
79688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
79432 KB |
Output is correct |
2 |
Correct |
163 ms |
79468 KB |
Output is correct |
3 |
Correct |
140 ms |
79656 KB |
Output is correct |
4 |
Correct |
109 ms |
79492 KB |
Output is correct |
5 |
Correct |
103 ms |
80792 KB |
Output is correct |
6 |
Correct |
130 ms |
79548 KB |
Output is correct |
7 |
Correct |
125 ms |
80204 KB |
Output is correct |
8 |
Correct |
134 ms |
79432 KB |
Output is correct |
9 |
Correct |
139 ms |
79432 KB |
Output is correct |
10 |
Correct |
98 ms |
78764 KB |
Output is correct |
11 |
Correct |
86 ms |
78756 KB |
Output is correct |
12 |
Correct |
110 ms |
78788 KB |
Output is correct |
13 |
Correct |
139 ms |
79944 KB |
Output is correct |
14 |
Correct |
92 ms |
79964 KB |
Output is correct |
15 |
Correct |
110 ms |
78920 KB |
Output is correct |
16 |
Correct |
118 ms |
78920 KB |
Output is correct |
17 |
Correct |
111 ms |
79260 KB |
Output is correct |
18 |
Correct |
138 ms |
79432 KB |
Output is correct |
19 |
Correct |
64 ms |
78920 KB |
Output is correct |
20 |
Correct |
136 ms |
79688 KB |
Output is correct |
21 |
Correct |
99 ms |
79944 KB |
Output is correct |
22 |
Correct |
149 ms |
80776 KB |
Output is correct |
23 |
Correct |
89 ms |
79996 KB |
Output is correct |
24 |
Correct |
96 ms |
79520 KB |
Output is correct |
25 |
Correct |
137 ms |
79688 KB |
Output is correct |
26 |
Correct |
108 ms |
79688 KB |
Output is correct |
27 |
Correct |
157 ms |
80184 KB |
Output is correct |
28 |
Correct |
76 ms |
79604 KB |
Output is correct |
29 |
Correct |
140 ms |
80796 KB |
Output is correct |
30 |
Correct |
130 ms |
80432 KB |
Output is correct |
31 |
Correct |
84 ms |
79432 KB |
Output is correct |
32 |
Correct |
112 ms |
79628 KB |
Output is correct |
33 |
Correct |
75 ms |
79688 KB |
Output is correct |
34 |
Correct |
136 ms |
80200 KB |
Output is correct |
35 |
Correct |
77 ms |
79620 KB |
Output is correct |
36 |
Correct |
143 ms |
80604 KB |
Output is correct |
37 |
Correct |
95 ms |
80712 KB |
Output is correct |
38 |
Correct |
122 ms |
79564 KB |
Output is correct |
39 |
Correct |
89 ms |
79636 KB |
Output is correct |
40 |
Correct |
113 ms |
79688 KB |
Output is correct |
41 |
Correct |
110 ms |
80200 KB |
Output is correct |
42 |
Correct |
130 ms |
79944 KB |
Output is correct |