#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n, q;
int p[100009];
int ans[10000001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n >> q;
for(int i = 0; i < n; ++i)
cin >> p[i];
reverse(p, p+n);
ans[0] = 0;
int lim = 1e4+1;
for(int i = 1; i < lim; ++i){
ans[i] = 1e9;
for(int j = 0; j <= n; ++j){
if(j == n){
lim = i;
break;
}
if(i%p[j] != 0){
ans[i] = min(ans[i], 1+ans[i-i%p[j]]);
}
}
}
while(q--){
int x;
cin >> x;
if(x >= lim)
cout << "oo\n";
else
cout << ans[x] << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
12 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
18 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
896 KB |
Output isn't correct |
3 |
Incorrect |
11 ms |
768 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
6 ms |
768 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
512 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
9 |
Incorrect |
8 ms |
768 KB |
Output isn't correct |
10 |
Incorrect |
7 ms |
768 KB |
Output isn't correct |
11 |
Incorrect |
6 ms |
640 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
15 |
Incorrect |
6 ms |
744 KB |
Output isn't correct |
16 |
Incorrect |
10 ms |
896 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
18 |
Incorrect |
11 ms |
896 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
896 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
768 KB |
Output isn't correct |
3 |
Incorrect |
12 ms |
896 KB |
Output isn't correct |
4 |
Incorrect |
15 ms |
768 KB |
Output isn't correct |
5 |
Incorrect |
26 ms |
1152 KB |
Output isn't correct |
6 |
Incorrect |
14 ms |
1024 KB |
Output isn't correct |
7 |
Incorrect |
20 ms |
1152 KB |
Output isn't correct |
8 |
Incorrect |
11 ms |
1024 KB |
Output isn't correct |
9 |
Incorrect |
11 ms |
896 KB |
Output isn't correct |
10 |
Incorrect |
3 ms |
512 KB |
Output isn't correct |
11 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
13 |
Incorrect |
16 ms |
1024 KB |
Output isn't correct |
14 |
Incorrect |
16 ms |
1024 KB |
Output isn't correct |
15 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
17 |
Incorrect |
7 ms |
896 KB |
Output isn't correct |
18 |
Incorrect |
11 ms |
896 KB |
Output isn't correct |
19 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
20 |
Incorrect |
13 ms |
1024 KB |
Output isn't correct |
21 |
Incorrect |
14 ms |
1024 KB |
Output isn't correct |
22 |
Incorrect |
23 ms |
1280 KB |
Output isn't correct |
23 |
Incorrect |
19 ms |
1024 KB |
Output isn't correct |
24 |
Incorrect |
13 ms |
896 KB |
Output isn't correct |
25 |
Incorrect |
15 ms |
896 KB |
Output isn't correct |
26 |
Incorrect |
15 ms |
896 KB |
Output isn't correct |
27 |
Incorrect |
17 ms |
1152 KB |
Output isn't correct |
28 |
Incorrect |
14 ms |
1024 KB |
Output isn't correct |
29 |
Incorrect |
23 ms |
1280 KB |
Output isn't correct |
30 |
Incorrect |
20 ms |
1272 KB |
Output isn't correct |
31 |
Incorrect |
14 ms |
896 KB |
Output isn't correct |
32 |
Incorrect |
13 ms |
896 KB |
Output isn't correct |
33 |
Incorrect |
12 ms |
896 KB |
Output isn't correct |
34 |
Incorrect |
18 ms |
1152 KB |
Output isn't correct |
35 |
Incorrect |
14 ms |
1024 KB |
Output isn't correct |
36 |
Incorrect |
22 ms |
1272 KB |
Output isn't correct |
37 |
Incorrect |
28 ms |
1280 KB |
Output isn't correct |
38 |
Incorrect |
13 ms |
1024 KB |
Output isn't correct |
39 |
Incorrect |
14 ms |
1024 KB |
Output isn't correct |
40 |
Incorrect |
14 ms |
1024 KB |
Output isn't correct |
41 |
Incorrect |
18 ms |
1152 KB |
Output isn't correct |
42 |
Incorrect |
14 ms |
1024 KB |
Output isn't correct |