Submission #31280

#TimeUsernameProblemLanguageResultExecution timeMemory
31280imaxblueBrunhilda’s Birthday (BOI13_brunhilda)C++14
67.14 / 100
529 ms81528 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define foxr1(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)

int n, q, x, c, t, lo=(1 << 30), dp[10000005], f[10000005];
vector<bool> p=vector<bool>(10000000);
int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);
    cout.tie(0);
    cout.sync_with_stdio(0);
    cin >> n >> q;
    fox(l, n){
        cin >> x;
        p[x]=1;
        lo=min(lo, 10000000/x*x);
    }
    for(int l=2; l<=10000000; ++l){
        if (f[l]!=0) continue;
        for (int l2=l; l2<=10000000; l2+=l){
            if (p[l]) f[l2]=l;
        }
    }
    foxr1(l, 10000000){
        t=lo;
        lo=min(lo, l-f[l]);
        f[l]=t;
        //cout << f[l] << endl;
    }
    fox1(l, 10000000){
        if (f[l]==l) dp[l]=(1 << 30);
        dp[l]=dp[f[l]]+1;
    }
    fox(l, q){
        cin >> x;
        if (dp[x]>=(1 << 30)){
            cout << "oo\n";
        }
        else {
            cout << dp[x] << endl;
        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...