Submission #92639

#TimeUsernameProblemLanguageResultExecution timeMemory
92639luckyboyBrunhilda’s Birthday (BOI13_brunhilda)C++14
10 / 100
1089 ms39660 KiB
/**Lucky Boy**/
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int  i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int  i = (a); i >= (b); --i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define maxc 1000000007
#define maxn 100005
#define maxm 10000007
#define pii pair <int,int>
#define Task ""
template <typename T> inline void read(T &x){char c;bool nega=0;while((!isdigit(c=getchar()))&&(c!='-'));if(c=='-'){nega=1;c=getchar();}x=c-48;while(isdigit(c=getchar())) x=x*10+c-48;if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10);putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){putchar('-');x=-x;}writep(x);putchar(' ');}
template <typename T> inline void writeln(T x){write(x);putchar('\n');}
using namespace std;
int n,q,a[maxn],tich = 1,dp[maxm];
int main()
{
    ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
    //freopen(Task".inp", "r",stdin);
    //freopen(Task".out", "w",stdout);
    cin >> n >> q;
    FOR(i,1,n)
    {
        cin >> a[i];
        if (1ll*tich*a[i] > 1e7)
        {
            tich = 1e7 + 1;
        }
        else tich *= a[i];
    }
    dp[0] = 0;
    FOR(i,1,tich - 1)
        {
            dp[i] = maxc;
            FOR(j,1,n)
            {
                int x = i / a[j];
                x *= a[j];
                dp[i] = min(dp[i],dp[x] + 1);
            }
        }
    while (q--)
    {
        int x;
        cin >> x;
        if (x >= tich)
        {
            cout << "oo\n";
        }
        else
        {
            cout << dp[x] << '\n';
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...