제출 #1026811

#제출 시각아이디문제언어결과실행 시간메모리
1026811VMaksimoski008Brunhilda’s Birthday (BOI13_brunhilda)C++17
100 / 100
205 ms80280 KiB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 5;

vector<int> dp(maxn, 1e9), L(maxn, 1e9);

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(0); cin.tie(0);

    int n, q;
    cin >> n >> q;

    vector<int> p(n);
    for(int &x : p) cin >> x;

    L[0] = 0; dp[0] = 0;
    for(int &x : p)
        for(int i=0; i*x<1e7; i++) L[min((int)1e7, (i+1)*x-1)] = min(L[min((int)1e7, (i+1)*x-1)] , i * x);
    for(int i=1e7-1; i>=1; i--) L[i] = min(L[i], L[i+1]);
    
    for(int i=1; i<=1e7; i++) {
        if(L[i] >= i) dp[i] = 1e9;
        else dp[i] = dp[L[i]] + 1;
    }

    while(q--) {
        int x;
        cin >> x;
        if(dp[x] < 1e9) cout << dp[x] << '\n';
        else cout << "oo\n";
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...