Submission #31287

#TimeUsernameProblemLanguageResultExecution timeMemory
31287imaxblueBrunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
459 ms81368 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, t, l2, k, lo=(1 << 30), dp[10000005], f[10000005];
vector<bool> p=vector<bool>(10000005);
int main(){
    scanf("%i%i", &n, &q);
    fox(l, n){
        scanf("%i", &x);
        p[x]=1;
        lo=min(lo, 10000000/x*x);
    }
    for(int l=2; l<=10000000; l++){
        if (f[l]!=0) continue;
        if (p[l]) k=l; else k=-1;
        if (k==-1){
            if (l>10000) continue;
            for (l2=l*l; l2<=10000000; l2+=l){
                f[l2]=(f[l2]==0) ? -1 : f[l2];
            }
        } else {
            for (l2=l; l2<=10000000; l2+=l){
                f[l2]=l;
            }
        }
    }
    foxr1(l, 10000000){
        t=lo;
        lo=min(lo, l-max(0, 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){
        scanf("%i", &x);
        if (dp[x]>=(1 << 30)){
            printf("oo\n");
        }
        else {
            printf("%i\n", dp[x]);
        }
    }
    return 0;
}

Compilation message (stderr)

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:29:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i", &n, &q);
                          ^
brunhilda.cpp:31:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i", &x);
                        ^
brunhilda.cpp:60:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i", &x);
                        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...