# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577107 | goodluck2020 | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 244 ms | 80264 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.
#define INPFILE "GROUP.INP"
#define OUTFILE "GROUP.OUT"
#include <bits/stdc++.h>
using namespace std;
bool maximise(int &a, int b) { return a < b ? a = b, true : false; }
const int MAX = 1e7 + 1, INF = 0x3f3f3f3f;
int n, Q, rmax[MAX], f[MAX];
bool used[MAX];
void input(void) {
cin >> n >> Q;
memset(rmax, 0, sizeof rmax);
for (int i = 1; i <= n; i++) {
int x; cin >> x;
if (used[x]) continue;
for (int j = x - 1; j < MAX; j += x)
maximise(rmax[j], x - 1);
maximise(rmax[MAX - 1], (MAX - 1) % x);
}
for (int i = MAX - 2; i >= 0; i--)
maximise(rmax[i], rmax[i + 1] - 1);
}
int main(void) {
if (fopen(INPFILE, "r")) {
freopen(INPFILE, "r", stdin);
freopen(OUTFILE, "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
input();
memset(f, 0x3f, sizeof f); f[0] = 0;
for (int i = 1; i < MAX; i++)
f[i] = f[i - rmax[i]] + 1;
while (Q--) {
int x; cin >> x;
int ans = f[x];
if (ans >= INF) cout << "oo\n";
else cout << ans << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |