#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i, a, b) for (int i=a;i>=b;--i)
const int MX_M = 1e5+5;
const int MX_Q = 1e5+5;
const int MX_P = 1e7+5;
const int infty = 1e9;
int M, Q, P[MX_M];
int pi[MX_P], dp[MX_P];
using ii = pair<int, int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> M >> Q;
FOR(i,1,M){
cin >> P[i];
for (int j = P[i]; j < MX_P; j += P[i]) pi[j-1] = P[i]-1;
}
RFOR(i,MX_P-2,0) pi[i] = max(pi[i],pi[i+1]-1);
dp[0] = 0;
FOR(i,1,MX_P-1) {
if (pi[i] == 0) dp[i] = infty;
else dp[i] = min(infty,dp[i-pi[i]]+1);
}
FOR(i,1,Q){
int N; cin >> N;
if (dp[N] == infty) cout << "oo" << '\n';
else cout << dp[N] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
78584 KB |
Output is correct |
2 |
Correct |
117 ms |
78580 KB |
Output is correct |
3 |
Correct |
109 ms |
78584 KB |
Output is correct |
4 |
Correct |
103 ms |
78584 KB |
Output is correct |
5 |
Correct |
109 ms |
78588 KB |
Output is correct |
6 |
Correct |
100 ms |
78584 KB |
Output is correct |
7 |
Correct |
116 ms |
78584 KB |
Output is correct |
8 |
Correct |
111 ms |
78584 KB |
Output is correct |
9 |
Correct |
126 ms |
78584 KB |
Output is correct |
10 |
Correct |
140 ms |
78584 KB |
Output is correct |
11 |
Correct |
136 ms |
78584 KB |
Output is correct |
12 |
Correct |
98 ms |
78584 KB |
Output is correct |
13 |
Correct |
211 ms |
78584 KB |
Output is correct |
14 |
Correct |
209 ms |
78584 KB |
Output is correct |
15 |
Correct |
123 ms |
78584 KB |
Output is correct |
16 |
Correct |
119 ms |
78584 KB |
Output is correct |
17 |
Correct |
118 ms |
78584 KB |
Output is correct |
18 |
Correct |
102 ms |
78712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
125 ms |
78712 KB |
Output is correct |
2 |
Correct |
131 ms |
78968 KB |
Output is correct |
3 |
Correct |
259 ms |
78840 KB |
Output is correct |
4 |
Correct |
126 ms |
78584 KB |
Output is correct |
5 |
Correct |
189 ms |
78844 KB |
Output is correct |
6 |
Correct |
118 ms |
78588 KB |
Output is correct |
7 |
Correct |
116 ms |
78712 KB |
Output is correct |
8 |
Correct |
125 ms |
78584 KB |
Output is correct |
9 |
Correct |
217 ms |
79224 KB |
Output is correct |
10 |
Correct |
256 ms |
78840 KB |
Output is correct |
11 |
Incorrect |
248 ms |
78712 KB |
Output isn't correct |
12 |
Correct |
157 ms |
78712 KB |
Output is correct |
13 |
Correct |
107 ms |
78584 KB |
Output is correct |
14 |
Correct |
127 ms |
78580 KB |
Output is correct |
15 |
Correct |
216 ms |
78840 KB |
Output is correct |
16 |
Correct |
130 ms |
78968 KB |
Output is correct |
17 |
Correct |
217 ms |
78584 KB |
Output is correct |
18 |
Correct |
218 ms |
78968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
227 ms |
78840 KB |
Output is correct |
2 |
Correct |
270 ms |
78840 KB |
Output is correct |
3 |
Correct |
273 ms |
79100 KB |
Output is correct |
4 |
Incorrect |
187 ms |
78968 KB |
Output isn't correct |
5 |
Incorrect |
162 ms |
79200 KB |
Output isn't correct |
6 |
Correct |
235 ms |
79096 KB |
Output is correct |
7 |
Correct |
214 ms |
79096 KB |
Output is correct |
8 |
Correct |
225 ms |
78840 KB |
Output is correct |
9 |
Correct |
231 ms |
79096 KB |
Output is correct |
10 |
Correct |
181 ms |
78712 KB |
Output is correct |
11 |
Incorrect |
159 ms |
78712 KB |
Output isn't correct |
12 |
Correct |
210 ms |
78712 KB |
Output is correct |
13 |
Correct |
276 ms |
78996 KB |
Output is correct |
14 |
Correct |
168 ms |
79224 KB |
Output is correct |
15 |
Incorrect |
221 ms |
78840 KB |
Output isn't correct |
16 |
Correct |
238 ms |
78712 KB |
Output is correct |
17 |
Correct |
208 ms |
78840 KB |
Output is correct |
18 |
Correct |
270 ms |
78968 KB |
Output is correct |
19 |
Incorrect |
115 ms |
78712 KB |
Output isn't correct |
20 |
Correct |
267 ms |
78960 KB |
Output is correct |
21 |
Incorrect |
186 ms |
79224 KB |
Output isn't correct |
22 |
Correct |
287 ms |
79224 KB |
Output is correct |
23 |
Correct |
162 ms |
78968 KB |
Output is correct |
24 |
Correct |
139 ms |
78968 KB |
Output is correct |
25 |
Correct |
236 ms |
78968 KB |
Output is correct |
26 |
Incorrect |
185 ms |
78840 KB |
Output isn't correct |
27 |
Correct |
291 ms |
79352 KB |
Output is correct |
28 |
Incorrect |
140 ms |
78968 KB |
Output isn't correct |
29 |
Correct |
274 ms |
79212 KB |
Output is correct |
30 |
Correct |
259 ms |
79096 KB |
Output is correct |
31 |
Correct |
151 ms |
78840 KB |
Output is correct |
32 |
Incorrect |
167 ms |
78968 KB |
Output isn't correct |
33 |
Incorrect |
125 ms |
78840 KB |
Output isn't correct |
34 |
Correct |
205 ms |
79096 KB |
Output is correct |
35 |
Incorrect |
136 ms |
78968 KB |
Output isn't correct |
36 |
Correct |
283 ms |
79096 KB |
Output is correct |
37 |
Incorrect |
161 ms |
79224 KB |
Output isn't correct |
38 |
Correct |
242 ms |
78972 KB |
Output is correct |
39 |
Incorrect |
143 ms |
78968 KB |
Output isn't correct |
40 |
Correct |
214 ms |
78968 KB |
Output is correct |
41 |
Correct |
194 ms |
79096 KB |
Output is correct |
42 |
Correct |
248 ms |
79096 KB |
Output is correct |