#include <iostream>
#include <vector>
#include <set>
#include <deque>
using namespace std;
const int lim = 1e7;
vector<int> res(lim+1, 1e9);
vector<int> factor(lim+1, 0);
int main()
{
int M, Q;
cin >> M >> Q;
int p[M];
for(int i = 0; i < M; i++)
{
cin >> p[i];
for(int q = 0; q <= lim; q += p[i]) factor[q] = max(factor[q], p[i]);
}
deque<int> pos, val;
pos.push_back(0);
val.push_back(0);
for(int i = 0; i <= lim; i++)
{
while(!pos.empty() && pos.front() < i)
{
pos.pop_front();
val.pop_front();
}
if(pos.empty()) break;
res[i] = val.front();
if(pos.back() < i + factor[i] - 1)
{
pos.push_back(i + factor[i] - 1);
val.push_back(res[i] + 1);
}
}
while(Q--)
{
int q;
cin >> q;
if(res[q] == 1e9) cout << "oo\n";
else cout << res[q] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
78700 KB |
Output is correct |
2 |
Correct |
150 ms |
78700 KB |
Output is correct |
3 |
Correct |
90 ms |
78572 KB |
Output is correct |
4 |
Correct |
119 ms |
78700 KB |
Output is correct |
5 |
Correct |
130 ms |
78700 KB |
Output is correct |
6 |
Correct |
66 ms |
78572 KB |
Output is correct |
7 |
Correct |
90 ms |
78572 KB |
Output is correct |
8 |
Correct |
105 ms |
78572 KB |
Output is correct |
9 |
Correct |
175 ms |
78700 KB |
Output is correct |
10 |
Correct |
184 ms |
78700 KB |
Output is correct |
11 |
Correct |
164 ms |
78700 KB |
Output is correct |
12 |
Correct |
95 ms |
78572 KB |
Output is correct |
13 |
Correct |
280 ms |
78572 KB |
Output is correct |
14 |
Correct |
302 ms |
78700 KB |
Output is correct |
15 |
Correct |
152 ms |
78700 KB |
Output is correct |
16 |
Correct |
151 ms |
78572 KB |
Output is correct |
17 |
Correct |
156 ms |
78700 KB |
Output is correct |
18 |
Correct |
129 ms |
78700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
78828 KB |
Output is correct |
2 |
Correct |
160 ms |
79980 KB |
Output is correct |
3 |
Correct |
366 ms |
79468 KB |
Output is correct |
4 |
Correct |
144 ms |
78572 KB |
Output is correct |
5 |
Correct |
256 ms |
79340 KB |
Output is correct |
6 |
Correct |
143 ms |
78700 KB |
Output is correct |
7 |
Correct |
120 ms |
78700 KB |
Output is correct |
8 |
Correct |
140 ms |
78752 KB |
Output is correct |
9 |
Correct |
294 ms |
79724 KB |
Output is correct |
10 |
Correct |
371 ms |
79564 KB |
Output is correct |
11 |
Correct |
355 ms |
79084 KB |
Output is correct |
12 |
Correct |
193 ms |
78572 KB |
Output is correct |
13 |
Correct |
109 ms |
78572 KB |
Output is correct |
14 |
Correct |
143 ms |
78572 KB |
Output is correct |
15 |
Correct |
330 ms |
79212 KB |
Output is correct |
16 |
Correct |
163 ms |
79980 KB |
Output is correct |
17 |
Correct |
291 ms |
78572 KB |
Output is correct |
18 |
Correct |
305 ms |
79980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
409 ms |
79724 KB |
Output is correct |
2 |
Correct |
431 ms |
79736 KB |
Output is correct |
3 |
Correct |
503 ms |
79852 KB |
Output is correct |
4 |
Correct |
430 ms |
79588 KB |
Output is correct |
5 |
Correct |
439 ms |
81132 KB |
Output is correct |
6 |
Correct |
524 ms |
79724 KB |
Output is correct |
7 |
Correct |
407 ms |
80620 KB |
Output is correct |
8 |
Correct |
405 ms |
79724 KB |
Output is correct |
9 |
Correct |
417 ms |
79724 KB |
Output is correct |
10 |
Correct |
254 ms |
78828 KB |
Output is correct |
11 |
Correct |
248 ms |
78828 KB |
Output is correct |
12 |
Correct |
317 ms |
78956 KB |
Output is correct |
13 |
Correct |
577 ms |
79980 KB |
Output is correct |
14 |
Correct |
456 ms |
79980 KB |
Output is correct |
15 |
Correct |
346 ms |
79084 KB |
Output is correct |
16 |
Correct |
374 ms |
78924 KB |
Output is correct |
17 |
Correct |
313 ms |
79468 KB |
Output is correct |
18 |
Correct |
452 ms |
79596 KB |
Output is correct |
19 |
Correct |
181 ms |
78828 KB |
Output is correct |
20 |
Correct |
513 ms |
79852 KB |
Output is correct |
21 |
Correct |
496 ms |
80328 KB |
Output is correct |
22 |
Correct |
634 ms |
81132 KB |
Output is correct |
23 |
Correct |
410 ms |
80108 KB |
Output is correct |
24 |
Correct |
368 ms |
79596 KB |
Output is correct |
25 |
Correct |
474 ms |
79792 KB |
Output is correct |
26 |
Correct |
435 ms |
79640 KB |
Output is correct |
27 |
Correct |
543 ms |
80492 KB |
Output is correct |
28 |
Correct |
381 ms |
79724 KB |
Output is correct |
29 |
Correct |
623 ms |
81260 KB |
Output is correct |
30 |
Correct |
564 ms |
80776 KB |
Output is correct |
31 |
Correct |
368 ms |
79596 KB |
Output is correct |
32 |
Correct |
402 ms |
79724 KB |
Output is correct |
33 |
Correct |
349 ms |
79596 KB |
Output is correct |
34 |
Correct |
410 ms |
80748 KB |
Output is correct |
35 |
Correct |
392 ms |
79852 KB |
Output is correct |
36 |
Correct |
629 ms |
80972 KB |
Output is correct |
37 |
Correct |
435 ms |
81404 KB |
Output is correct |
38 |
Correct |
531 ms |
79724 KB |
Output is correct |
39 |
Correct |
392 ms |
79852 KB |
Output is correct |
40 |
Correct |
478 ms |
79852 KB |
Output is correct |
41 |
Correct |
391 ms |
80492 KB |
Output is correct |
42 |
Correct |
581 ms |
79820 KB |
Output is correct |