#include <bits/stdc++.h>
using namespace std;
const int P = 1e7+10;
const int M = 1e5+10;
struct Node {
int v;
Node * nxt;
};
int mx;
Node * q[P];
int dp[P];
Node* add(Node * no, int x) {
return new Node({x, no});
}
void clear(Node * no) {
if(no == 0) return;
clear(no->nxt);
delete no;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int m, Q;
cin >> m >> Q;
for(int i = 0; i < m; i++) {
int x;
cin >> x;
q[0] = add(q[0], x);
}
for(int i = 1; i < P; i++) dp[i] = 1e9+10;
for(int i = 0; i < P; i++) {
Node* cur = q[i];
while(cur) {
int p = cur->v;
int nxt = i+p;
int til = min(nxt, P);
for(int j = max(mx, i+1); j < til; j++) {
dp[j] = dp[i]+1;
}
mx = max(mx, nxt);
// fast jump
nxt = mx / p * p;
if(nxt < P) q[nxt] = add(q[nxt], p);
cur = cur->nxt;
}
}
for(int i = 0; i < Q; i++) {
int x;
cin >> x;
if(dp[x] > 1e9) cout << "oo" << endl;
else cout << dp[x] << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
173944 KB |
Output is correct |
2 |
Correct |
202 ms |
173944 KB |
Output is correct |
3 |
Correct |
262 ms |
174636 KB |
Output is correct |
4 |
Correct |
160 ms |
174636 KB |
Output is correct |
5 |
Correct |
268 ms |
174636 KB |
Output is correct |
6 |
Correct |
260 ms |
174636 KB |
Output is correct |
7 |
Correct |
282 ms |
174728 KB |
Output is correct |
8 |
Correct |
327 ms |
179868 KB |
Output is correct |
9 |
Correct |
325 ms |
201828 KB |
Output is correct |
10 |
Correct |
249 ms |
201828 KB |
Output is correct |
11 |
Correct |
277 ms |
201828 KB |
Output is correct |
12 |
Correct |
162 ms |
201828 KB |
Output is correct |
13 |
Correct |
229 ms |
201828 KB |
Output is correct |
14 |
Correct |
244 ms |
201828 KB |
Output is correct |
15 |
Correct |
197 ms |
201828 KB |
Output is correct |
16 |
Correct |
208 ms |
201828 KB |
Output is correct |
17 |
Correct |
229 ms |
201828 KB |
Output is correct |
18 |
Correct |
160 ms |
201828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
201828 KB |
Output is correct |
2 |
Correct |
132 ms |
201828 KB |
Output is correct |
3 |
Correct |
202 ms |
201828 KB |
Output is correct |
4 |
Correct |
169 ms |
201828 KB |
Output is correct |
5 |
Correct |
222 ms |
201828 KB |
Output is correct |
6 |
Correct |
145 ms |
201828 KB |
Output is correct |
7 |
Correct |
156 ms |
201828 KB |
Output is correct |
8 |
Correct |
163 ms |
201828 KB |
Output is correct |
9 |
Correct |
268 ms |
201828 KB |
Output is correct |
10 |
Correct |
202 ms |
201828 KB |
Output is correct |
11 |
Correct |
238 ms |
201828 KB |
Output is correct |
12 |
Correct |
176 ms |
201828 KB |
Output is correct |
13 |
Correct |
135 ms |
201828 KB |
Output is correct |
14 |
Correct |
166 ms |
201828 KB |
Output is correct |
15 |
Correct |
304 ms |
201828 KB |
Output is correct |
16 |
Correct |
176 ms |
201828 KB |
Output is correct |
17 |
Correct |
197 ms |
201828 KB |
Output is correct |
18 |
Correct |
162 ms |
201828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
337 ms |
201828 KB |
Output is correct |
2 |
Correct |
347 ms |
201828 KB |
Output is correct |
3 |
Correct |
378 ms |
201828 KB |
Output is correct |
4 |
Correct |
323 ms |
201828 KB |
Output is correct |
5 |
Correct |
355 ms |
201828 KB |
Output is correct |
6 |
Correct |
377 ms |
201828 KB |
Output is correct |
7 |
Correct |
329 ms |
201828 KB |
Output is correct |
8 |
Correct |
346 ms |
201828 KB |
Output is correct |
9 |
Correct |
323 ms |
201828 KB |
Output is correct |
10 |
Correct |
222 ms |
201828 KB |
Output is correct |
11 |
Correct |
233 ms |
201828 KB |
Output is correct |
12 |
Correct |
244 ms |
201828 KB |
Output is correct |
13 |
Correct |
418 ms |
201828 KB |
Output is correct |
14 |
Correct |
524 ms |
211176 KB |
Output is correct |
15 |
Correct |
286 ms |
211176 KB |
Output is correct |
16 |
Correct |
297 ms |
211176 KB |
Output is correct |
17 |
Correct |
285 ms |
211176 KB |
Output is correct |
18 |
Correct |
367 ms |
211176 KB |
Output is correct |
19 |
Correct |
193 ms |
211176 KB |
Output is correct |
20 |
Correct |
367 ms |
211176 KB |
Output is correct |
21 |
Correct |
372 ms |
211176 KB |
Output is correct |
22 |
Correct |
530 ms |
211176 KB |
Output is correct |
23 |
Correct |
385 ms |
211176 KB |
Output is correct |
24 |
Correct |
320 ms |
211176 KB |
Output is correct |
25 |
Correct |
397 ms |
211176 KB |
Output is correct |
26 |
Correct |
326 ms |
211176 KB |
Output is correct |
27 |
Correct |
421 ms |
211176 KB |
Output is correct |
28 |
Correct |
286 ms |
211176 KB |
Output is correct |
29 |
Correct |
488 ms |
211176 KB |
Output is correct |
30 |
Correct |
484 ms |
211176 KB |
Output is correct |
31 |
Correct |
297 ms |
211176 KB |
Output is correct |
32 |
Correct |
356 ms |
211176 KB |
Output is correct |
33 |
Correct |
306 ms |
211176 KB |
Output is correct |
34 |
Correct |
357 ms |
211176 KB |
Output is correct |
35 |
Correct |
329 ms |
211176 KB |
Output is correct |
36 |
Correct |
510 ms |
211176 KB |
Output is correct |
37 |
Correct |
359 ms |
211176 KB |
Output is correct |
38 |
Correct |
378 ms |
211176 KB |
Output is correct |
39 |
Correct |
324 ms |
211176 KB |
Output is correct |
40 |
Correct |
361 ms |
211176 KB |
Output is correct |
41 |
Correct |
265 ms |
211176 KB |
Output is correct |
42 |
Correct |
386 ms |
211176 KB |
Output is correct |