# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36502 | cheater2k | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 499 ms | 80140 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>
using namespace std;
const int MAX = 10000000;
const int inf = 1e9 + 10;
int nprime, nquery;
int maxdiv[MAX + 5];
int dp[MAX + 5];
int main() {
scanf("%d %d", &nprime, &nquery);
for (int i = 1; i <= MAX; ++i) dp[i] = inf;
for (int i = 1; i <= nprime; ++i) {
int p; scanf("%d", &p);
for (int j = 0; j <= MAX; j += p) maxdiv[j] = p;
}
int cur = 0;
for (int i = 1; i <= MAX; ++i) {
while(cur < i) {
if (!maxdiv[cur] || cur + maxdiv[cur] <= i) ++cur;
else break;
}
if (cur == i) continue;
dp[i] = min(dp[i], dp[cur] + 1);
}
while(nquery--) {
int n; scanf("%d", &n);
if (dp[n] != inf) printf("%d\n", dp[n]);
else printf("oo\n");
}
}
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... |