#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1e9;
const int maxn = 1e7 + 5;
int m, q;
vector<int> primes;
int dp[maxn];
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> m >> q;
for (int i = 0; i < m; ++i) {
int p;
cin >> p;
primes.push_back(p);
}
for (int x = 1; x < maxn; ++x) {
int bestp = -1;
for (int j = m-1; j >= max(0, m-10); --j) {
if (x % primes[j] != 0) {
bestp = primes[j];
break;
}
}
if (bestp == -1) {
dp[x] = inf;
} else {
//if (x < 10)
//cout << x << " -> " << x - (x%bestp) << endl;
dp[x] = 1 + dp[x - (x % bestp)];
}
}
while (q--) {
int x;
cin >> x;
if (dp[x] < inf) cout << dp[x] << endl;
else cout << "oo\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
126 ms |
39416 KB |
Output isn't correct |
2 |
Incorrect |
116 ms |
39600 KB |
Output isn't correct |
3 |
Incorrect |
119 ms |
39452 KB |
Output isn't correct |
4 |
Incorrect |
149 ms |
39800 KB |
Output isn't correct |
5 |
Incorrect |
119 ms |
39564 KB |
Output isn't correct |
6 |
Incorrect |
118 ms |
39416 KB |
Output isn't correct |
7 |
Incorrect |
119 ms |
39416 KB |
Output isn't correct |
8 |
Incorrect |
124 ms |
39392 KB |
Output isn't correct |
9 |
Incorrect |
120 ms |
39544 KB |
Output isn't correct |
10 |
Incorrect |
118 ms |
39420 KB |
Output isn't correct |
11 |
Incorrect |
119 ms |
39632 KB |
Output isn't correct |
12 |
Correct |
115 ms |
39416 KB |
Output is correct |
13 |
Incorrect |
120 ms |
39536 KB |
Output isn't correct |
14 |
Incorrect |
139 ms |
39544 KB |
Output isn't correct |
15 |
Incorrect |
116 ms |
39520 KB |
Output isn't correct |
16 |
Incorrect |
116 ms |
39516 KB |
Output isn't correct |
17 |
Incorrect |
142 ms |
39544 KB |
Output isn't correct |
18 |
Incorrect |
141 ms |
39552 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
117 ms |
39612 KB |
Output isn't correct |
2 |
Correct |
126 ms |
40664 KB |
Output is correct |
3 |
Correct |
124 ms |
40436 KB |
Output is correct |
4 |
Incorrect |
116 ms |
39536 KB |
Output isn't correct |
5 |
Correct |
121 ms |
40184 KB |
Output is correct |
6 |
Incorrect |
115 ms |
39544 KB |
Output isn't correct |
7 |
Incorrect |
120 ms |
39672 KB |
Output isn't correct |
8 |
Incorrect |
115 ms |
39544 KB |
Output isn't correct |
9 |
Incorrect |
123 ms |
40436 KB |
Output isn't correct |
10 |
Correct |
123 ms |
40436 KB |
Output is correct |
11 |
Incorrect |
119 ms |
40056 KB |
Output isn't correct |
12 |
Incorrect |
115 ms |
39568 KB |
Output isn't correct |
13 |
Incorrect |
115 ms |
39544 KB |
Output isn't correct |
14 |
Incorrect |
115 ms |
39544 KB |
Output isn't correct |
15 |
Incorrect |
120 ms |
40056 KB |
Output isn't correct |
16 |
Correct |
127 ms |
40792 KB |
Output is correct |
17 |
Incorrect |
116 ms |
39544 KB |
Output isn't correct |
18 |
Incorrect |
127 ms |
40692 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
236 ms |
40568 KB |
Output isn't correct |
2 |
Incorrect |
191 ms |
40440 KB |
Output isn't correct |
3 |
Incorrect |
270 ms |
40784 KB |
Output isn't correct |
4 |
Incorrect |
368 ms |
40568 KB |
Output isn't correct |
5 |
Incorrect |
408 ms |
41844 KB |
Output isn't correct |
6 |
Incorrect |
384 ms |
40660 KB |
Output isn't correct |
7 |
Incorrect |
282 ms |
41292 KB |
Output isn't correct |
8 |
Incorrect |
241 ms |
40732 KB |
Output isn't correct |
9 |
Incorrect |
244 ms |
40564 KB |
Output isn't correct |
10 |
Incorrect |
147 ms |
39672 KB |
Output isn't correct |
11 |
Incorrect |
178 ms |
39772 KB |
Output isn't correct |
12 |
Incorrect |
178 ms |
39800 KB |
Output isn't correct |
13 |
Incorrect |
365 ms |
40824 KB |
Output isn't correct |
14 |
Incorrect |
377 ms |
40704 KB |
Output isn't correct |
15 |
Incorrect |
197 ms |
39800 KB |
Output isn't correct |
16 |
Incorrect |
176 ms |
39944 KB |
Output isn't correct |
17 |
Incorrect |
158 ms |
40312 KB |
Output isn't correct |
18 |
Incorrect |
194 ms |
40480 KB |
Output isn't correct |
19 |
Incorrect |
177 ms |
39800 KB |
Output isn't correct |
20 |
Incorrect |
276 ms |
40760 KB |
Output isn't correct |
21 |
Incorrect |
398 ms |
40996 KB |
Output isn't correct |
22 |
Incorrect |
432 ms |
41844 KB |
Output isn't correct |
23 |
Incorrect |
419 ms |
40928 KB |
Output isn't correct |
24 |
Incorrect |
388 ms |
40696 KB |
Output isn't correct |
25 |
Incorrect |
384 ms |
40708 KB |
Output isn't correct |
26 |
Incorrect |
368 ms |
40532 KB |
Output isn't correct |
27 |
Incorrect |
289 ms |
41340 KB |
Output isn't correct |
28 |
Incorrect |
391 ms |
40808 KB |
Output isn't correct |
29 |
Incorrect |
432 ms |
41968 KB |
Output isn't correct |
30 |
Incorrect |
431 ms |
41716 KB |
Output isn't correct |
31 |
Incorrect |
379 ms |
40712 KB |
Output isn't correct |
32 |
Incorrect |
388 ms |
40656 KB |
Output isn't correct |
33 |
Incorrect |
371 ms |
40568 KB |
Output isn't correct |
34 |
Incorrect |
276 ms |
41252 KB |
Output isn't correct |
35 |
Incorrect |
388 ms |
40696 KB |
Output isn't correct |
36 |
Incorrect |
416 ms |
41728 KB |
Output isn't correct |
37 |
Incorrect |
409 ms |
41940 KB |
Output isn't correct |
38 |
Incorrect |
386 ms |
40656 KB |
Output isn't correct |
39 |
Incorrect |
400 ms |
40568 KB |
Output isn't correct |
40 |
Incorrect |
377 ms |
40676 KB |
Output isn't correct |
41 |
Correct |
278 ms |
41204 KB |
Output is correct |
42 |
Incorrect |
388 ms |
40728 KB |
Output isn't correct |