# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
631376 | anhduc2701 | Brunhilda’s Birthday (BOI13_brunhilda) | C++17 | 571 ms | 157352 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 int long long
using namespace std;
const int maxn = 2e7 + 10;
const int INF = 1e10;
int dp[maxn];
int n, m;
signed main()
{
cin.tie(0),cout.tie(0)->sync_with_stdio;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
int p;
cin >> p;
for (int j = p - 1; j < maxn; j += p)
{
dp[j] = p - 1;
}
}
for (int i = maxn - 2; i > 0; i--)
{
dp[i] = max(dp[i + 1] - 1, dp[i]);
}
for (int i = 1; i < maxn; i++)
{
if (dp[i] > 0)
{
dp[i] = dp[i - dp[i]] + 1;
}
else
{
dp[i] = INF;
}
}
for (int i = 1; i <= m; i++)
{
int q;
cin >> q;
if(dp[q]>=INF){
cout<<"oo"<<'\n';
}
else{
cout<<dp[q]<<"\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... |