#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
fast;
int n,t;
cin>>n>>t;
vi p(n),lp(1e7 + 5);
vi dp(1e7 + 5);
for (int i = 0;i<n;i++){
cin>>p[i];
for (int j = 0;j<=1e7;j+=p[i])lp[j] = p[i];
}
int ptr = 0;
deque<int>a;
a.push_back(0);
for (int i = 1;i<=1e7;i++){
while (ptr + lp[ptr] <= i)ptr++;
while (!a.empty() && a.front() < ptr)a.pop_front();
if (a.empty())dp[i] = 1e7 + 5;
else dp[i] = 1 + dp[a.front()];
while (!a.empty() && dp[a.back()] > dp[i])a.pop_back();
a.push_back(i);
}
while (t--){
int n;
cin>>n;
if (dp[n] > 1e7)cout<<"oo"<<'\n';
else cout<<dp[n]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
78572 KB |
Output is correct |
2 |
Correct |
179 ms |
78572 KB |
Output is correct |
3 |
Correct |
177 ms |
78700 KB |
Output is correct |
4 |
Correct |
145 ms |
78700 KB |
Output is correct |
5 |
Correct |
169 ms |
78700 KB |
Output is correct |
6 |
Correct |
183 ms |
78572 KB |
Output is correct |
7 |
Correct |
182 ms |
78700 KB |
Output is correct |
8 |
Correct |
186 ms |
78700 KB |
Output is correct |
9 |
Correct |
206 ms |
78700 KB |
Output is correct |
10 |
Correct |
211 ms |
78700 KB |
Output is correct |
11 |
Correct |
197 ms |
78700 KB |
Output is correct |
12 |
Correct |
149 ms |
78700 KB |
Output is correct |
13 |
Correct |
305 ms |
78700 KB |
Output is correct |
14 |
Correct |
300 ms |
78700 KB |
Output is correct |
15 |
Correct |
183 ms |
78744 KB |
Output is correct |
16 |
Correct |
190 ms |
78572 KB |
Output is correct |
17 |
Correct |
166 ms |
78740 KB |
Output is correct |
18 |
Correct |
139 ms |
78828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
82540 KB |
Output is correct |
2 |
Correct |
214 ms |
116720 KB |
Output is correct |
3 |
Correct |
348 ms |
89852 KB |
Output is correct |
4 |
Correct |
179 ms |
79084 KB |
Output is correct |
5 |
Correct |
258 ms |
84588 KB |
Output is correct |
6 |
Correct |
171 ms |
78956 KB |
Output is correct |
7 |
Correct |
161 ms |
82668 KB |
Output is correct |
8 |
Correct |
174 ms |
78700 KB |
Output is correct |
9 |
Correct |
290 ms |
84716 KB |
Output is correct |
10 |
Correct |
358 ms |
89708 KB |
Output is correct |
11 |
Correct |
346 ms |
82936 KB |
Output is correct |
12 |
Correct |
225 ms |
78828 KB |
Output is correct |
13 |
Correct |
152 ms |
80876 KB |
Output is correct |
14 |
Correct |
177 ms |
79084 KB |
Output is correct |
15 |
Correct |
304 ms |
82412 KB |
Output is correct |
16 |
Correct |
185 ms |
116592 KB |
Output is correct |
17 |
Correct |
309 ms |
79212 KB |
Output is correct |
18 |
Correct |
299 ms |
100256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
83692 KB |
Output is correct |
2 |
Correct |
389 ms |
82668 KB |
Output is correct |
3 |
Correct |
359 ms |
83780 KB |
Output is correct |
4 |
Correct |
253 ms |
80108 KB |
Output is correct |
5 |
Correct |
231 ms |
99104 KB |
Output is correct |
6 |
Correct |
323 ms |
80364 KB |
Output is correct |
7 |
Correct |
296 ms |
92028 KB |
Output is correct |
8 |
Correct |
315 ms |
83728 KB |
Output is correct |
9 |
Correct |
308 ms |
83820 KB |
Output is correct |
10 |
Correct |
266 ms |
79364 KB |
Output is correct |
11 |
Correct |
218 ms |
79340 KB |
Output is correct |
12 |
Correct |
272 ms |
79340 KB |
Output is correct |
13 |
Correct |
354 ms |
83308 KB |
Output is correct |
14 |
Correct |
238 ms |
79980 KB |
Output is correct |
15 |
Correct |
294 ms |
79340 KB |
Output is correct |
16 |
Correct |
323 ms |
79340 KB |
Output is correct |
17 |
Correct |
282 ms |
82668 KB |
Output is correct |
18 |
Correct |
354 ms |
82480 KB |
Output is correct |
19 |
Correct |
199 ms |
82028 KB |
Output is correct |
20 |
Correct |
351 ms |
83756 KB |
Output is correct |
21 |
Correct |
262 ms |
79980 KB |
Output is correct |
22 |
Correct |
383 ms |
87164 KB |
Output is correct |
23 |
Correct |
205 ms |
84076 KB |
Output is correct |
24 |
Correct |
187 ms |
80228 KB |
Output is correct |
25 |
Correct |
264 ms |
79980 KB |
Output is correct |
26 |
Correct |
251 ms |
79980 KB |
Output is correct |
27 |
Correct |
380 ms |
87408 KB |
Output is correct |
28 |
Correct |
176 ms |
80492 KB |
Output is correct |
29 |
Correct |
348 ms |
87036 KB |
Output is correct |
30 |
Correct |
329 ms |
84716 KB |
Output is correct |
31 |
Correct |
199 ms |
80752 KB |
Output is correct |
32 |
Correct |
216 ms |
79980 KB |
Output is correct |
33 |
Correct |
172 ms |
80492 KB |
Output is correct |
34 |
Correct |
277 ms |
92028 KB |
Output is correct |
35 |
Correct |
186 ms |
80492 KB |
Output is correct |
36 |
Correct |
370 ms |
87100 KB |
Output is correct |
37 |
Correct |
227 ms |
99104 KB |
Output is correct |
38 |
Correct |
308 ms |
80236 KB |
Output is correct |
39 |
Correct |
189 ms |
80236 KB |
Output is correct |
40 |
Correct |
279 ms |
80492 KB |
Output is correct |
41 |
Correct |
263 ms |
110576 KB |
Output is correct |
42 |
Correct |
329 ms |
80108 KB |
Output is correct |