//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
//#define endl '\n'
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 1e7 + 2;
int dp[N];
int max_p[N];
void solve(){
int m, q;
cin >> m >> q;
while (m--){
int p;
cin >> p;
for (int i = 0; i < N; i += p) max_p[i] = p;
}
fill(dp + 1, dp + N, 1e9);
int l = 0, r = 0;
int val = 0;
while (r < N){
if (l > r) break;
int nxt_r = r;
for (int i = l; i <= r; i++){
dp[i] = val;
int p = max_p[i];
if (p == 0) continue;
nxt_r = max(nxt_r, i + p - 1);
}
nxt_r = min(nxt_r, N - 1);
l = r + 1;
r = nxt_r;
val++;
}
while (q--){
int i;
cin >> i;
if (dp[i] != 1e9){
cout << dp[i] << "\n";
} else {
cout << "oo\n";
}
}
}
int main(){
clock_t startTime = clock();
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int test_cases = 1;
// cin >> test_cases;
for (int test = 1; test <= test_cases; test++){
// cout << (solve() ? "YES" : "NO") << endl;
solve();
}
#ifdef LOCAL
cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;
#endif
return 0;
}
Compilation message
brunhilda.cpp: In function 'int main()':
brunhilda.cpp:70:13: warning: unused variable 'startTime' [-Wunused-variable]
70 | clock_t startTime = clock();
| ^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
78540 KB |
Output is correct |
2 |
Correct |
66 ms |
78588 KB |
Output is correct |
3 |
Correct |
48 ms |
78500 KB |
Output is correct |
4 |
Correct |
66 ms |
78508 KB |
Output is correct |
5 |
Correct |
79 ms |
78580 KB |
Output is correct |
6 |
Correct |
40 ms |
78472 KB |
Output is correct |
7 |
Correct |
47 ms |
78504 KB |
Output is correct |
8 |
Correct |
51 ms |
78500 KB |
Output is correct |
9 |
Correct |
87 ms |
78492 KB |
Output is correct |
10 |
Correct |
95 ms |
78492 KB |
Output is correct |
11 |
Correct |
104 ms |
78488 KB |
Output is correct |
12 |
Correct |
49 ms |
78488 KB |
Output is correct |
13 |
Correct |
143 ms |
78488 KB |
Output is correct |
14 |
Correct |
152 ms |
78496 KB |
Output is correct |
15 |
Correct |
84 ms |
78584 KB |
Output is correct |
16 |
Correct |
67 ms |
78540 KB |
Output is correct |
17 |
Correct |
96 ms |
78504 KB |
Output is correct |
18 |
Correct |
63 ms |
78540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
78500 KB |
Output is correct |
2 |
Correct |
90 ms |
78492 KB |
Output is correct |
3 |
Correct |
181 ms |
78588 KB |
Output is correct |
4 |
Correct |
104 ms |
78588 KB |
Output is correct |
5 |
Correct |
133 ms |
78488 KB |
Output is correct |
6 |
Correct |
72 ms |
78472 KB |
Output is correct |
7 |
Correct |
70 ms |
78584 KB |
Output is correct |
8 |
Correct |
109 ms |
78508 KB |
Output is correct |
9 |
Correct |
153 ms |
78488 KB |
Output is correct |
10 |
Correct |
178 ms |
78540 KB |
Output is correct |
11 |
Correct |
184 ms |
78544 KB |
Output is correct |
12 |
Correct |
121 ms |
78488 KB |
Output is correct |
13 |
Correct |
63 ms |
78532 KB |
Output is correct |
14 |
Correct |
101 ms |
78508 KB |
Output is correct |
15 |
Correct |
145 ms |
78516 KB |
Output is correct |
16 |
Correct |
90 ms |
78496 KB |
Output is correct |
17 |
Correct |
148 ms |
78560 KB |
Output is correct |
18 |
Correct |
155 ms |
78508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
78620 KB |
Output is correct |
2 |
Correct |
212 ms |
78624 KB |
Output is correct |
3 |
Correct |
244 ms |
78796 KB |
Output is correct |
4 |
Correct |
244 ms |
78796 KB |
Output is correct |
5 |
Correct |
225 ms |
78752 KB |
Output is correct |
6 |
Correct |
266 ms |
78844 KB |
Output is correct |
7 |
Correct |
213 ms |
78672 KB |
Output is correct |
8 |
Correct |
200 ms |
78616 KB |
Output is correct |
9 |
Correct |
194 ms |
78660 KB |
Output is correct |
10 |
Correct |
155 ms |
78612 KB |
Output is correct |
11 |
Correct |
154 ms |
78624 KB |
Output is correct |
12 |
Correct |
165 ms |
78676 KB |
Output is correct |
13 |
Correct |
279 ms |
78752 KB |
Output is correct |
14 |
Correct |
224 ms |
79128 KB |
Output is correct |
15 |
Correct |
171 ms |
78620 KB |
Output is correct |
16 |
Correct |
183 ms |
78624 KB |
Output is correct |
17 |
Correct |
167 ms |
78500 KB |
Output is correct |
18 |
Correct |
207 ms |
78540 KB |
Output is correct |
19 |
Correct |
90 ms |
78680 KB |
Output is correct |
20 |
Correct |
251 ms |
78872 KB |
Output is correct |
21 |
Correct |
245 ms |
79212 KB |
Output is correct |
22 |
Correct |
315 ms |
78744 KB |
Output is correct |
23 |
Correct |
229 ms |
78756 KB |
Output is correct |
24 |
Correct |
201 ms |
78968 KB |
Output is correct |
25 |
Correct |
242 ms |
78876 KB |
Output is correct |
26 |
Correct |
232 ms |
78748 KB |
Output is correct |
27 |
Correct |
261 ms |
78748 KB |
Output is correct |
28 |
Correct |
204 ms |
78812 KB |
Output is correct |
29 |
Correct |
311 ms |
78744 KB |
Output is correct |
30 |
Correct |
292 ms |
78792 KB |
Output is correct |
31 |
Correct |
214 ms |
78780 KB |
Output is correct |
32 |
Correct |
239 ms |
78796 KB |
Output is correct |
33 |
Correct |
174 ms |
78716 KB |
Output is correct |
34 |
Correct |
219 ms |
78760 KB |
Output is correct |
35 |
Correct |
205 ms |
78892 KB |
Output is correct |
36 |
Correct |
310 ms |
78668 KB |
Output is correct |
37 |
Correct |
237 ms |
78696 KB |
Output is correct |
38 |
Correct |
269 ms |
78748 KB |
Output is correct |
39 |
Correct |
210 ms |
78820 KB |
Output is correct |
40 |
Correct |
245 ms |
78864 KB |
Output is correct |
41 |
Correct |
204 ms |
78620 KB |
Output is correct |
42 |
Correct |
304 ms |
79028 KB |
Output is correct |