# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134018 | CaroLinda | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 1092 ms | 40824 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 lp(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
const int MAXM = 1e5+10 ;
const int MAX = 1e7+10 ;
using namespace std ;
int v[MAXM] , dp[MAX] ;
int m , q ;
int solve(int x)
{
if(x <= 0) return 0 ;
if(dp[x] != -1) return dp[x] ;
int maior = 0 ;
lp(i,0,m) maior = max(maior, x%v[i] ) ;
if(maior==0) return -2 ;
int k = solve(x-maior) ;
if(k == -2) return dp[x] = k ;
return dp[x] = k+1 ;
}
int main()
{
memset(dp,-1,sizeof dp) ;
scanf("%d%d", &m, &q) ;
lp(i,0,m) scanf("%d", &v[i]) ;
lp(i,0,q)
{
int x ;
scanf("%d", &x ) ;
int ans = solve(x) ;
if(ans==-2) printf("oo\n") ;
else printf("%d\n", ans ) ;
}
}
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... |