#include "bits/stdc++.h"
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
const int MXN = 1e7;
int jmp[MXN+2], ans[MXN+2];
int main() {
#ifdef shiven
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int m, q; cin >> m >> q;
for_(i, 0, m) {
int k; cin >> k;
for (int j = k; j <= MXN; j += k) {
jmp[j-1] = max(jmp[j-1], k-1);
}
}
for (int i = MXN; i >= 1; i--) jmp[i] = max(jmp[i], jmp[i+1]-1);
for_(i, 1, MXN+1) if (jmp[i] and (ans[i-jmp[i]] or i == jmp[i])) ans[i] = ans[i-jmp[i]]+1;
for_(i, 0, q) {
int k; cin >> k;
if (ans[k]) cout << ans[k];
else cout << "oo";
cout << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
39524 KB |
Output is correct |
2 |
Correct |
133 ms |
78692 KB |
Output is correct |
3 |
Correct |
111 ms |
40548 KB |
Output is correct |
4 |
Correct |
109 ms |
78564 KB |
Output is correct |
5 |
Correct |
122 ms |
78564 KB |
Output is correct |
6 |
Correct |
98 ms |
39524 KB |
Output is correct |
7 |
Correct |
112 ms |
40548 KB |
Output is correct |
8 |
Correct |
116 ms |
43108 KB |
Output is correct |
9 |
Correct |
140 ms |
78564 KB |
Output is correct |
10 |
Correct |
161 ms |
78564 KB |
Output is correct |
11 |
Correct |
157 ms |
78692 KB |
Output is correct |
12 |
Correct |
109 ms |
78584 KB |
Output is correct |
13 |
Correct |
253 ms |
78564 KB |
Output is correct |
14 |
Correct |
258 ms |
78692 KB |
Output is correct |
15 |
Correct |
141 ms |
78564 KB |
Output is correct |
16 |
Correct |
134 ms |
78708 KB |
Output is correct |
17 |
Correct |
133 ms |
78692 KB |
Output is correct |
18 |
Correct |
109 ms |
78564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
78564 KB |
Output is correct |
2 |
Correct |
140 ms |
78564 KB |
Output is correct |
3 |
Correct |
307 ms |
78564 KB |
Output is correct |
4 |
Correct |
145 ms |
78564 KB |
Output is correct |
5 |
Correct |
226 ms |
78564 KB |
Output is correct |
6 |
Correct |
131 ms |
78564 KB |
Output is correct |
7 |
Correct |
124 ms |
78564 KB |
Output is correct |
8 |
Correct |
149 ms |
78564 KB |
Output is correct |
9 |
Correct |
269 ms |
78564 KB |
Output is correct |
10 |
Correct |
307 ms |
78692 KB |
Output is correct |
11 |
Incorrect |
301 ms |
78692 KB |
Output isn't correct |
12 |
Correct |
179 ms |
78564 KB |
Output is correct |
13 |
Correct |
114 ms |
78564 KB |
Output is correct |
14 |
Correct |
145 ms |
78600 KB |
Output is correct |
15 |
Correct |
255 ms |
78564 KB |
Output is correct |
16 |
Correct |
140 ms |
78564 KB |
Output is correct |
17 |
Correct |
259 ms |
78568 KB |
Output is correct |
18 |
Incorrect |
254 ms |
78692 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
263 ms |
78692 KB |
Output is correct |
2 |
Correct |
320 ms |
78692 KB |
Output is correct |
3 |
Correct |
323 ms |
78948 KB |
Output is correct |
4 |
Incorrect |
211 ms |
78820 KB |
Output isn't correct |
5 |
Incorrect |
173 ms |
78948 KB |
Output isn't correct |
6 |
Correct |
272 ms |
78948 KB |
Output is correct |
7 |
Correct |
245 ms |
78820 KB |
Output is correct |
8 |
Correct |
265 ms |
78948 KB |
Output is correct |
9 |
Correct |
265 ms |
78820 KB |
Output is correct |
10 |
Correct |
212 ms |
78692 KB |
Output is correct |
11 |
Incorrect |
187 ms |
78820 KB |
Output isn't correct |
12 |
Correct |
246 ms |
78692 KB |
Output is correct |
13 |
Correct |
305 ms |
78948 KB |
Output is correct |
14 |
Correct |
191 ms |
79204 KB |
Output is correct |
15 |
Incorrect |
254 ms |
78696 KB |
Output isn't correct |
16 |
Correct |
282 ms |
78820 KB |
Output is correct |
17 |
Correct |
259 ms |
78692 KB |
Output is correct |
18 |
Correct |
355 ms |
78672 KB |
Output is correct |
19 |
Incorrect |
133 ms |
78692 KB |
Output isn't correct |
20 |
Correct |
329 ms |
78820 KB |
Output is correct |
21 |
Incorrect |
225 ms |
79460 KB |
Output isn't correct |
22 |
Correct |
341 ms |
78948 KB |
Output is correct |
23 |
Correct |
177 ms |
78948 KB |
Output is correct |
24 |
Correct |
149 ms |
79076 KB |
Output is correct |
25 |
Incorrect |
243 ms |
78948 KB |
Output isn't correct |
26 |
Incorrect |
212 ms |
78944 KB |
Output isn't correct |
27 |
Correct |
352 ms |
78820 KB |
Output is correct |
28 |
Incorrect |
142 ms |
78948 KB |
Output isn't correct |
29 |
Correct |
328 ms |
78952 KB |
Output is correct |
30 |
Correct |
293 ms |
78948 KB |
Output is correct |
31 |
Correct |
164 ms |
78820 KB |
Output is correct |
32 |
Incorrect |
184 ms |
79076 KB |
Output isn't correct |
33 |
Incorrect |
134 ms |
78820 KB |
Output isn't correct |
34 |
Correct |
245 ms |
78692 KB |
Output is correct |
35 |
Incorrect |
152 ms |
79076 KB |
Output isn't correct |
36 |
Correct |
324 ms |
78948 KB |
Output is correct |
37 |
Incorrect |
173 ms |
78820 KB |
Output isn't correct |
38 |
Correct |
278 ms |
78948 KB |
Output is correct |
39 |
Incorrect |
158 ms |
78952 KB |
Output isn't correct |
40 |
Correct |
238 ms |
78820 KB |
Output is correct |
41 |
Correct |
214 ms |
78692 KB |
Output is correct |
42 |
Incorrect |
291 ms |
79076 KB |
Output isn't correct |