#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 5;
vector<int> dp(maxn, 1e9), L(maxn, 1e9);
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> p(n);
for(int &x : p) cin >> x;
L[0] = 0; dp[0] = 0;
for(int &x : p)
for(int i=0; i*x<1e7; i++) L[min((int)1e7, (i+1)*x-1)] = min(L[min((int)1e7, (i+1)*x-1)] , i * x);
for(int i=1e7-1; i>=1; i--) L[i] = min(L[i], L[i+1]);
for(int i=1; i<=1e7; i++) {
if(L[i] >= i) dp[i] = 1e9;
else dp[i] = dp[L[i]] + 1;
}
while(q--) {
int x;
cin >> x;
if(dp[x] < 1e9) cout << dp[x] << '\n';
else cout << "oo\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
78680 KB |
Output is correct |
2 |
Correct |
76 ms |
78724 KB |
Output is correct |
3 |
Correct |
84 ms |
78680 KB |
Output is correct |
4 |
Correct |
53 ms |
78684 KB |
Output is correct |
5 |
Correct |
61 ms |
78680 KB |
Output is correct |
6 |
Correct |
53 ms |
78684 KB |
Output is correct |
7 |
Correct |
71 ms |
78684 KB |
Output is correct |
8 |
Correct |
71 ms |
78680 KB |
Output is correct |
9 |
Correct |
81 ms |
78680 KB |
Output is correct |
10 |
Correct |
131 ms |
78672 KB |
Output is correct |
11 |
Correct |
108 ms |
78684 KB |
Output is correct |
12 |
Correct |
69 ms |
78676 KB |
Output is correct |
13 |
Correct |
158 ms |
78612 KB |
Output is correct |
14 |
Correct |
159 ms |
78728 KB |
Output is correct |
15 |
Correct |
121 ms |
78724 KB |
Output is correct |
16 |
Correct |
84 ms |
78728 KB |
Output is correct |
17 |
Correct |
70 ms |
78740 KB |
Output is correct |
18 |
Correct |
56 ms |
78744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
78680 KB |
Output is correct |
2 |
Correct |
93 ms |
78936 KB |
Output is correct |
3 |
Correct |
205 ms |
78796 KB |
Output is correct |
4 |
Correct |
94 ms |
78672 KB |
Output is correct |
5 |
Correct |
121 ms |
79192 KB |
Output is correct |
6 |
Correct |
76 ms |
78680 KB |
Output is correct |
7 |
Correct |
62 ms |
78680 KB |
Output is correct |
8 |
Correct |
73 ms |
78680 KB |
Output is correct |
9 |
Correct |
129 ms |
79396 KB |
Output is correct |
10 |
Correct |
157 ms |
79432 KB |
Output is correct |
11 |
Correct |
148 ms |
78936 KB |
Output is correct |
12 |
Correct |
93 ms |
78680 KB |
Output is correct |
13 |
Correct |
59 ms |
78684 KB |
Output is correct |
14 |
Correct |
76 ms |
78920 KB |
Output is correct |
15 |
Correct |
121 ms |
79196 KB |
Output is correct |
16 |
Correct |
72 ms |
79564 KB |
Output is correct |
17 |
Correct |
128 ms |
78684 KB |
Output is correct |
18 |
Correct |
131 ms |
79484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
79320 KB |
Output is correct |
2 |
Correct |
160 ms |
79440 KB |
Output is correct |
3 |
Correct |
163 ms |
79440 KB |
Output is correct |
4 |
Correct |
104 ms |
79336 KB |
Output is correct |
5 |
Correct |
83 ms |
80208 KB |
Output is correct |
6 |
Correct |
138 ms |
79444 KB |
Output is correct |
7 |
Correct |
124 ms |
80028 KB |
Output is correct |
8 |
Correct |
133 ms |
79312 KB |
Output is correct |
9 |
Correct |
138 ms |
79440 KB |
Output is correct |
10 |
Correct |
101 ms |
78684 KB |
Output is correct |
11 |
Correct |
90 ms |
78928 KB |
Output is correct |
12 |
Correct |
125 ms |
78864 KB |
Output is correct |
13 |
Correct |
150 ms |
79696 KB |
Output is correct |
14 |
Correct |
100 ms |
79700 KB |
Output is correct |
15 |
Correct |
134 ms |
78996 KB |
Output is correct |
16 |
Correct |
141 ms |
78928 KB |
Output is correct |
17 |
Correct |
123 ms |
79308 KB |
Output is correct |
18 |
Correct |
160 ms |
79440 KB |
Output is correct |
19 |
Correct |
66 ms |
78928 KB |
Output is correct |
20 |
Correct |
154 ms |
79444 KB |
Output is correct |
21 |
Correct |
113 ms |
80044 KB |
Output is correct |
22 |
Correct |
192 ms |
80220 KB |
Output is correct |
23 |
Correct |
79 ms |
79788 KB |
Output is correct |
24 |
Correct |
76 ms |
79444 KB |
Output is correct |
25 |
Correct |
117 ms |
79440 KB |
Output is correct |
26 |
Correct |
111 ms |
79444 KB |
Output is correct |
27 |
Correct |
179 ms |
79756 KB |
Output is correct |
28 |
Correct |
76 ms |
79700 KB |
Output is correct |
29 |
Correct |
172 ms |
80116 KB |
Output is correct |
30 |
Correct |
143 ms |
79952 KB |
Output is correct |
31 |
Correct |
81 ms |
79440 KB |
Output is correct |
32 |
Correct |
96 ms |
79696 KB |
Output is correct |
33 |
Correct |
70 ms |
79440 KB |
Output is correct |
34 |
Correct |
113 ms |
79956 KB |
Output is correct |
35 |
Correct |
84 ms |
79696 KB |
Output is correct |
36 |
Correct |
170 ms |
80280 KB |
Output is correct |
37 |
Correct |
96 ms |
80208 KB |
Output is correct |
38 |
Correct |
130 ms |
79356 KB |
Output is correct |
39 |
Correct |
82 ms |
79696 KB |
Output is correct |
40 |
Correct |
124 ms |
79468 KB |
Output is correct |
41 |
Correct |
109 ms |
79952 KB |
Output is correct |
42 |
Correct |
148 ms |
79872 KB |
Output is correct |