# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26491 | samir_droubi | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 1000 ms | 11520 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;
int n,q;
map<int,int>dp;
const int mxn=(1e5)+5;
int a[mxn];
int mx=0;
int get(int up,int pr)
{
if(up%pr==0)return -1;
int dif=up-pr;
int ans=pr+dif/pr;
return ans;
}
int calc(int x)
{
if(x<mx)return 1;
if(dp.count(x))return dp[x];
int ans=(1e9);
for(int i=0;i<n;++i)
{
int num=get(x,a[i]);
if(num==-1)continue;
ans=1+min(ans,calc(num));
}
return dp[x]=ans;
}
int main()
{
scanf("%d%d",&n,&q);
for(int i=0;i<n;++i)
{
scanf("%d",&a[i]);
mx=max(mx,a[i]);
}
for(int i=0;i<q;++i)
{
int x;
scanf("%d",&x);
int ans=calc(x);
if(ans==(1e9))printf("oo\n");
else printf("%d\n",ans);
}
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... |