# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239420 | luciocf | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 334 ms | 42232 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 maxn = 1e5+10;
const int maxv = 1e7+10;
int p[maxn];
int dp[maxv];
int main(void)
{
int n, q;
scanf("%d %d", &n, &q);
int prod = 1;
for (int i = 0; i < maxv; i++)
dp[i] = 2*maxv;
for (int i = 1; i <= n; i++)
{
scanf("%d", &p[i]);
if (prod != maxv)
{
if (1ll*prod*p[i] > 1ll*maxv)
prod = maxv;
else
prod *= p[i];
}
for (int j = 0; j < maxv; j += p[i])
{
int a = min(maxv-1, j+p[i]-1);
dp[a] = min(dp[a], j);
}
}
for (int i = maxv-2; i >= 0; i--)
dp[i] = min(dp[i], dp[i+1]);
while (q--)
{
int x;
scanf("%d", &x);
if (prod <= x)
{
printf("oo\n");
continue;
}
printf("%d\n", dp[x]);
}
}
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... |