제출 #31859

#제출 시각아이디문제언어결과실행 시간메모리
31859minhtung0404Brunhilda’s Birthday (BOI13_brunhilda)C++14
55.71 / 100
619 ms80532 KiB
#include<bits/stdc++.h>
const int N = 1e5 + 5;
const int M = 1e7 + 5;
const int inf = 1e9;
using namespace std;

int n, q, p[N], m, prime[M], ans[M], cnt = 1, ct;

int main(){
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++){
        for (int j = 0; j < M; j+=p[i]) prime[j] = max(prime[j], p[i]);
    }
    for (int i = 1; i < M; i++) ans[i] = -inf;
    while(ct < M){
        if (ans[ct] < 0) break;
        while(cnt < ct + prime[ct] && cnt < M) ans[cnt] = ans[ct] + 1, cnt++;
        ct++;
    }
    while(q--){
        cin >> m;
        if (ans[m] <= 0) cout << "oo\n";
        else cout << ans[m] << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...