# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74689 | kjain_1810 | Brunhilda’s Birthday (BOI13_brunhilda) | C++17 | 349 ms | 78528 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 f first
#define s second
#define pb push_back
#define ind(n) scanf("%d", &n)
#define ind2(n, m) scanf("%d%d", &n, &m)
#define ind3(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define inlld(n) scanf("%lld", &n)
#define inlld2(n, m) scanf("%lld%lld", &n, &m)
#define inlld3(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
using namespace std;
const int N=1e7+5;
const int MOD=1e9+7;
typedef long long ll;
typedef long double ld;
int n, q;
int arr[N], dp[N];
int solve(int i)
{
if(i==0)
return 0;
if(dp[i]!=-1)
return dp[i];
int ans=-1e8, best=0;
if(q==1)
{
for(int a=n; a>=1; a--)
{
if(i%arr[a]==0)
continue;
if(i%arr[a]>ans)
{
ans=i%arr[a];
best=a;
}
}
}
else
{
for(int a=n; a>=max(1, n-500); a--)
{
if(i%arr[a]==0)
continue;
if(i%arr[a]>ans)
{
ans=i%arr[a];
best=a;
}
}
}
if(best)
return dp[i]=solve(i-ans)+1;
else
return 1e8;
}
signed main()
{
ind2(n, q);
for(int a=1; a<=n; a++)
ind(arr[a]);
memset(dp, -1, sizeof(dp));
while(q--)
{
int x;
ind(x);
int ans=solve(x);
if(ans<1e8)
printf("%d\n", ans);
else
printf("oo\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... |