#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int M = 1e7 + 2;
const int inf = 1e9;
int dp[M], gde[M];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
int x; cin >> x;
for (int j = x - 1; j < M; j += x) gde[j] = x - 1;
}
for (int i = M - 2; i >= 1; i--) {
smax(gde[i], gde[i + 1] - 1);
}
for (int i = 1; i < M; i++) {
dp[i] = inf;
if (dp[i - gde[i]] != inf) dp[i] = dp[i - gde[i]] + 1;
}
for (int i = 1; i <= q; i++) {
int x; cin >> x;
if (dp[x] == inf) cout << "oo" << en;
else cout << dp[x] << en;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
78540 KB |
Output is correct |
2 |
Correct |
101 ms |
78540 KB |
Output is correct |
3 |
Correct |
87 ms |
78500 KB |
Output is correct |
4 |
Correct |
85 ms |
78500 KB |
Output is correct |
5 |
Correct |
91 ms |
78484 KB |
Output is correct |
6 |
Correct |
83 ms |
78480 KB |
Output is correct |
7 |
Correct |
94 ms |
78484 KB |
Output is correct |
8 |
Correct |
99 ms |
78488 KB |
Output is correct |
9 |
Correct |
105 ms |
78500 KB |
Output is correct |
10 |
Correct |
125 ms |
78604 KB |
Output is correct |
11 |
Correct |
109 ms |
78480 KB |
Output is correct |
12 |
Correct |
80 ms |
78484 KB |
Output is correct |
13 |
Correct |
177 ms |
78480 KB |
Output is correct |
14 |
Correct |
195 ms |
78492 KB |
Output is correct |
15 |
Correct |
103 ms |
78568 KB |
Output is correct |
16 |
Correct |
98 ms |
78480 KB |
Output is correct |
17 |
Correct |
101 ms |
78488 KB |
Output is correct |
18 |
Correct |
90 ms |
78540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
78484 KB |
Output is correct |
2 |
Correct |
102 ms |
78556 KB |
Output is correct |
3 |
Correct |
259 ms |
78484 KB |
Output is correct |
4 |
Correct |
113 ms |
78552 KB |
Output is correct |
5 |
Correct |
164 ms |
78484 KB |
Output is correct |
6 |
Correct |
97 ms |
78556 KB |
Output is correct |
7 |
Correct |
94 ms |
78480 KB |
Output is correct |
8 |
Correct |
115 ms |
78512 KB |
Output is correct |
9 |
Correct |
211 ms |
78496 KB |
Output is correct |
10 |
Correct |
214 ms |
78476 KB |
Output is correct |
11 |
Incorrect |
203 ms |
78484 KB |
Output isn't correct |
12 |
Correct |
131 ms |
78540 KB |
Output is correct |
13 |
Correct |
93 ms |
78476 KB |
Output is correct |
14 |
Correct |
108 ms |
78512 KB |
Output is correct |
15 |
Correct |
183 ms |
78504 KB |
Output is correct |
16 |
Correct |
116 ms |
78516 KB |
Output is correct |
17 |
Correct |
185 ms |
78576 KB |
Output is correct |
18 |
Correct |
175 ms |
78480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
192 ms |
78628 KB |
Output is correct |
2 |
Correct |
223 ms |
78608 KB |
Output is correct |
3 |
Correct |
222 ms |
78620 KB |
Output is correct |
4 |
Incorrect |
155 ms |
78820 KB |
Output isn't correct |
5 |
Incorrect |
134 ms |
78740 KB |
Output isn't correct |
6 |
Correct |
201 ms |
78768 KB |
Output is correct |
7 |
Correct |
172 ms |
78612 KB |
Output is correct |
8 |
Correct |
195 ms |
78608 KB |
Output is correct |
9 |
Correct |
191 ms |
78696 KB |
Output is correct |
10 |
Correct |
154 ms |
78624 KB |
Output is correct |
11 |
Incorrect |
134 ms |
78612 KB |
Output isn't correct |
12 |
Correct |
177 ms |
78600 KB |
Output is correct |
13 |
Correct |
230 ms |
78740 KB |
Output is correct |
14 |
Correct |
146 ms |
79112 KB |
Output is correct |
15 |
Incorrect |
196 ms |
78608 KB |
Output isn't correct |
16 |
Correct |
223 ms |
78612 KB |
Output is correct |
17 |
Correct |
169 ms |
78616 KB |
Output is correct |
18 |
Correct |
226 ms |
78668 KB |
Output is correct |
19 |
Incorrect |
101 ms |
78616 KB |
Output isn't correct |
20 |
Correct |
219 ms |
78740 KB |
Output is correct |
21 |
Incorrect |
170 ms |
79112 KB |
Output isn't correct |
22 |
Correct |
247 ms |
78736 KB |
Output is correct |
23 |
Correct |
136 ms |
78736 KB |
Output is correct |
24 |
Correct |
120 ms |
78752 KB |
Output is correct |
25 |
Incorrect |
164 ms |
78868 KB |
Output isn't correct |
26 |
Incorrect |
153 ms |
78740 KB |
Output isn't correct |
27 |
Correct |
245 ms |
78576 KB |
Output is correct |
28 |
Incorrect |
113 ms |
78796 KB |
Output isn't correct |
29 |
Correct |
223 ms |
78740 KB |
Output is correct |
30 |
Correct |
235 ms |
78796 KB |
Output is correct |
31 |
Correct |
126 ms |
78796 KB |
Output is correct |
32 |
Incorrect |
128 ms |
78756 KB |
Output isn't correct |
33 |
Incorrect |
105 ms |
78740 KB |
Output isn't correct |
34 |
Correct |
198 ms |
78616 KB |
Output is correct |
35 |
Incorrect |
118 ms |
78852 KB |
Output isn't correct |
36 |
Correct |
233 ms |
78856 KB |
Output is correct |
37 |
Incorrect |
137 ms |
78736 KB |
Output isn't correct |
38 |
Correct |
217 ms |
78744 KB |
Output is correct |
39 |
Incorrect |
115 ms |
78924 KB |
Output isn't correct |
40 |
Correct |
197 ms |
78744 KB |
Output is correct |
41 |
Correct |
173 ms |
78636 KB |
Output is correct |
42 |
Incorrect |
197 ms |
78872 KB |
Output isn't correct |