# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
155869 | HellAngel | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define Task "test"
#define pb emplace_back
using namespace std;
const int N = int(1e7) + 1;
const int inf = int(1e9);
int nxt[N], f[N], m, Q, n, x;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
cin >> m >> Q;
while(m --) {
cin >> x;
for(int i = x; i <= N; i += x) nxt[i - 1] = max(nxt[i - 1], x - 1);
nxt[N - 1] = max(nxt[N - 1], (N - 1) % x);
}
for(int i = N - 1; i >= 1; --i) nxt[i] = max(nxt[i], nxt[i + 1] - 1);
for(int i = 1; i < N; ++i) {
if(nxt[i]) f[i] = f[i - nxt[i]] + 1;
else f[i] = inf;
}
while(Q --) {
cin >> x;
if(f[x] >= inf) cout << "oo\n";
else cout << f[x] << '\n';
}