#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e7 + 5;
vector<int> dp(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;
dp[0] = 0;
for(int i=1; i<=1000; i++) {
for(int &x : p) {
if(i % x == 0) continue;
dp[i] = min(dp[i], dp[(i/x)*x] + 1);
}
}
while(q--) {
int x;
cin >> x;
if(dp[x] < 1e9) cout << dp[x] << '\n';
else cout << "oo\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
39516 KB |
Output isn't correct |
2 |
Incorrect |
7 ms |
39516 KB |
Output isn't correct |
3 |
Incorrect |
8 ms |
39516 KB |
Output isn't correct |
4 |
Incorrect |
8 ms |
39516 KB |
Output isn't correct |
5 |
Correct |
8 ms |
39532 KB |
Output is correct |
6 |
Incorrect |
8 ms |
39516 KB |
Output isn't correct |
7 |
Incorrect |
7 ms |
39516 KB |
Output isn't correct |
8 |
Incorrect |
7 ms |
39516 KB |
Output isn't correct |
9 |
Correct |
8 ms |
39516 KB |
Output is correct |
10 |
Incorrect |
7 ms |
39408 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
39516 KB |
Output isn't correct |
12 |
Incorrect |
8 ms |
39516 KB |
Output isn't correct |
13 |
Incorrect |
10 ms |
39604 KB |
Output isn't correct |
14 |
Incorrect |
11 ms |
39516 KB |
Output isn't correct |
15 |
Incorrect |
10 ms |
39564 KB |
Output isn't correct |
16 |
Incorrect |
7 ms |
39516 KB |
Output isn't correct |
17 |
Incorrect |
8 ms |
39516 KB |
Output isn't correct |
18 |
Incorrect |
8 ms |
39516 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
39516 KB |
Output isn't correct |
2 |
Incorrect |
223 ms |
40540 KB |
Output isn't correct |
3 |
Incorrect |
171 ms |
40284 KB |
Output isn't correct |
4 |
Incorrect |
15 ms |
39516 KB |
Output isn't correct |
5 |
Incorrect |
127 ms |
40276 KB |
Output isn't correct |
6 |
Incorrect |
10 ms |
39516 KB |
Output isn't correct |
7 |
Incorrect |
37 ms |
39516 KB |
Output isn't correct |
8 |
Incorrect |
10 ms |
39516 KB |
Output isn't correct |
9 |
Incorrect |
173 ms |
40284 KB |
Output isn't correct |
10 |
Incorrect |
172 ms |
40284 KB |
Output isn't correct |
11 |
Incorrect |
100 ms |
40028 KB |
Output isn't correct |
12 |
Incorrect |
12 ms |
39516 KB |
Output isn't correct |
13 |
Incorrect |
16 ms |
39620 KB |
Output isn't correct |
14 |
Incorrect |
18 ms |
39516 KB |
Output isn't correct |
15 |
Incorrect |
105 ms |
40028 KB |
Output isn't correct |
16 |
Incorrect |
220 ms |
40788 KB |
Output isn't correct |
17 |
Incorrect |
14 ms |
39516 KB |
Output isn't correct |
18 |
Incorrect |
234 ms |
40540 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
132 ms |
40532 KB |
Output isn't correct |
2 |
Incorrect |
133 ms |
40284 KB |
Output isn't correct |
3 |
Incorrect |
129 ms |
40532 KB |
Output isn't correct |
4 |
Incorrect |
27 ms |
40420 KB |
Output isn't correct |
5 |
Incorrect |
234 ms |
41556 KB |
Output isn't correct |
6 |
Incorrect |
47 ms |
40636 KB |
Output isn't correct |
7 |
Incorrect |
236 ms |
41256 KB |
Output isn't correct |
8 |
Incorrect |
130 ms |
40376 KB |
Output isn't correct |
9 |
Incorrect |
129 ms |
40532 KB |
Output isn't correct |
10 |
Incorrect |
25 ms |
39772 KB |
Output isn't correct |
11 |
Incorrect |
23 ms |
39764 KB |
Output isn't correct |
12 |
Incorrect |
24 ms |
39748 KB |
Output isn't correct |
13 |
Incorrect |
84 ms |
40844 KB |
Output isn't correct |
14 |
Incorrect |
15 ms |
40556 KB |
Output isn't correct |
15 |
Incorrect |
25 ms |
39772 KB |
Output isn't correct |
16 |
Incorrect |
28 ms |
39764 KB |
Output isn't correct |
17 |
Incorrect |
114 ms |
40160 KB |
Output isn't correct |
18 |
Incorrect |
128 ms |
40284 KB |
Output isn't correct |
19 |
Incorrect |
22 ms |
39764 KB |
Output isn't correct |
20 |
Incorrect |
129 ms |
40544 KB |
Output isn't correct |
21 |
Incorrect |
15 ms |
40540 KB |
Output isn't correct |
22 |
Incorrect |
245 ms |
41636 KB |
Output isn't correct |
23 |
Incorrect |
86 ms |
40788 KB |
Output isn't correct |
24 |
Incorrect |
21 ms |
40540 KB |
Output isn't correct |
25 |
Incorrect |
29 ms |
40488 KB |
Output isn't correct |
26 |
Incorrect |
26 ms |
40540 KB |
Output isn't correct |
27 |
Incorrect |
246 ms |
41128 KB |
Output isn't correct |
28 |
Incorrect |
17 ms |
40540 KB |
Output isn't correct |
29 |
Incorrect |
247 ms |
41644 KB |
Output isn't correct |
30 |
Incorrect |
183 ms |
41304 KB |
Output isn't correct |
31 |
Incorrect |
30 ms |
40532 KB |
Output isn't correct |
32 |
Incorrect |
25 ms |
40532 KB |
Output isn't correct |
33 |
Incorrect |
22 ms |
40532 KB |
Output isn't correct |
34 |
Incorrect |
242 ms |
41300 KB |
Output isn't correct |
35 |
Incorrect |
20 ms |
40540 KB |
Output isn't correct |
36 |
Incorrect |
236 ms |
41592 KB |
Output isn't correct |
37 |
Incorrect |
247 ms |
41624 KB |
Output isn't correct |
38 |
Incorrect |
39 ms |
40532 KB |
Output isn't correct |
39 |
Incorrect |
27 ms |
40684 KB |
Output isn't correct |
40 |
Incorrect |
39 ms |
40532 KB |
Output isn't correct |
41 |
Incorrect |
245 ms |
41300 KB |
Output isn't correct |
42 |
Incorrect |
24 ms |
40532 KB |
Output isn't correct |