#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
#define fr first
#define se second
int inf = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 1e7 + 10;
int dp[MAXN + 10], trans[MAXN + 10];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
for (int j = (a - 1); j <= MAXN; j += a) {
trans[j] = a - 1;
}
trans[MAXN] = max(trans[MAXN], MAXN % a);
}
for (int i = MAXN; i >= 1; i--) {
trans[i] = max(trans[i], trans[i + 1] - 1);
}
for (int i = 1; i <= MAXN; i++) {
dp[i] = inf;
dp[i] = min(dp[i], dp[i - trans[i]] + 1);
}
while (q--) {
int x;
cin >> x;
if (dp[x] == inf) cout << "oo\n";
else cout << dp[x] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
156844 KB |
Output is correct |
2 |
Correct |
73 ms |
156928 KB |
Output is correct |
3 |
Correct |
75 ms |
156756 KB |
Output is correct |
4 |
Correct |
66 ms |
156760 KB |
Output is correct |
5 |
Correct |
72 ms |
156756 KB |
Output is correct |
6 |
Correct |
79 ms |
156752 KB |
Output is correct |
7 |
Correct |
74 ms |
156752 KB |
Output is correct |
8 |
Correct |
80 ms |
156756 KB |
Output is correct |
9 |
Correct |
85 ms |
156752 KB |
Output is correct |
10 |
Correct |
96 ms |
156756 KB |
Output is correct |
11 |
Correct |
87 ms |
156800 KB |
Output is correct |
12 |
Correct |
64 ms |
156752 KB |
Output is correct |
13 |
Correct |
117 ms |
156756 KB |
Output is correct |
14 |
Correct |
124 ms |
156756 KB |
Output is correct |
15 |
Correct |
91 ms |
156752 KB |
Output is correct |
16 |
Correct |
84 ms |
156880 KB |
Output is correct |
17 |
Correct |
74 ms |
157008 KB |
Output is correct |
18 |
Correct |
69 ms |
156784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
156932 KB |
Output is correct |
2 |
Correct |
83 ms |
156752 KB |
Output is correct |
3 |
Correct |
141 ms |
156756 KB |
Output is correct |
4 |
Correct |
78 ms |
156756 KB |
Output is correct |
5 |
Correct |
119 ms |
156752 KB |
Output is correct |
6 |
Correct |
78 ms |
157012 KB |
Output is correct |
7 |
Correct |
76 ms |
156920 KB |
Output is correct |
8 |
Correct |
73 ms |
156824 KB |
Output is correct |
9 |
Correct |
126 ms |
156804 KB |
Output is correct |
10 |
Correct |
150 ms |
156756 KB |
Output is correct |
11 |
Correct |
141 ms |
156756 KB |
Output is correct |
12 |
Correct |
97 ms |
156756 KB |
Output is correct |
13 |
Correct |
72 ms |
156756 KB |
Output is correct |
14 |
Correct |
81 ms |
156752 KB |
Output is correct |
15 |
Correct |
135 ms |
156808 KB |
Output is correct |
16 |
Correct |
82 ms |
156752 KB |
Output is correct |
17 |
Correct |
127 ms |
156752 KB |
Output is correct |
18 |
Correct |
132 ms |
156804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
129 ms |
157016 KB |
Output is correct |
2 |
Correct |
153 ms |
157008 KB |
Output is correct |
3 |
Correct |
182 ms |
157316 KB |
Output is correct |
4 |
Correct |
119 ms |
157012 KB |
Output is correct |
5 |
Correct |
112 ms |
157008 KB |
Output is correct |
6 |
Correct |
152 ms |
157780 KB |
Output is correct |
7 |
Correct |
125 ms |
157012 KB |
Output is correct |
8 |
Correct |
140 ms |
157312 KB |
Output is correct |
9 |
Correct |
137 ms |
157008 KB |
Output is correct |
10 |
Correct |
105 ms |
156892 KB |
Output is correct |
11 |
Correct |
101 ms |
156816 KB |
Output is correct |
12 |
Correct |
130 ms |
157060 KB |
Output is correct |
13 |
Correct |
148 ms |
157776 KB |
Output is correct |
14 |
Correct |
107 ms |
157520 KB |
Output is correct |
15 |
Correct |
130 ms |
157012 KB |
Output is correct |
16 |
Correct |
137 ms |
157016 KB |
Output is correct |
17 |
Correct |
124 ms |
157008 KB |
Output is correct |
18 |
Correct |
153 ms |
157008 KB |
Output is correct |
19 |
Correct |
96 ms |
156816 KB |
Output is correct |
20 |
Correct |
176 ms |
157268 KB |
Output is correct |
21 |
Correct |
125 ms |
157520 KB |
Output is correct |
22 |
Correct |
193 ms |
157580 KB |
Output is correct |
23 |
Correct |
112 ms |
157068 KB |
Output is correct |
24 |
Correct |
114 ms |
157168 KB |
Output is correct |
25 |
Correct |
121 ms |
157324 KB |
Output is correct |
26 |
Correct |
120 ms |
157072 KB |
Output is correct |
27 |
Correct |
174 ms |
157212 KB |
Output is correct |
28 |
Correct |
95 ms |
157304 KB |
Output is correct |
29 |
Correct |
166 ms |
157588 KB |
Output is correct |
30 |
Correct |
149 ms |
157848 KB |
Output is correct |
31 |
Correct |
114 ms |
157076 KB |
Output is correct |
32 |
Correct |
109 ms |
157268 KB |
Output is correct |
33 |
Correct |
81 ms |
157208 KB |
Output is correct |
34 |
Correct |
131 ms |
157012 KB |
Output is correct |
35 |
Correct |
87 ms |
157072 KB |
Output is correct |
36 |
Correct |
180 ms |
157520 KB |
Output is correct |
37 |
Correct |
112 ms |
157016 KB |
Output is correct |
38 |
Correct |
145 ms |
157592 KB |
Output is correct |
39 |
Correct |
102 ms |
157264 KB |
Output is correct |
40 |
Correct |
147 ms |
157776 KB |
Output is correct |
41 |
Correct |
114 ms |
157056 KB |
Output is correct |
42 |
Correct |
143 ms |
158032 KB |
Output is correct |