제출 #494644

#제출 시각아이디문제언어결과실행 시간메모리
494644SirCovidThe19thBrunhilda’s Birthday (BOI13_brunhilda)C++17
100 / 100
558 ms157436 KiB
#include <bits/stdc++.h>
using namespace std;

const int mx = 2e7 + 5;
 
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); 
    int n, q; cin >> n >> q; 
    int A[n], bst[mx] = {}, dp[mx];
    for (int i = 0; i < n; i++){
        cin >> A[i];
        for (int mul = A[i] - 1; mul < mx; mul += A[i]) bst[mul] = max(bst[mul], A[i] - 1);
    }
    for (int i = mx - 2; i; i--) bst[i] = max(bst[i], bst[i + 1] - 1);

    fill(dp, dp + mx, 1e9); dp[0] = 0; 
    for (int i = 1; i < mx; i++) dp[i] = dp[i - bst[i]] + 1;
    
    while (q--){
        int x; cin >> x;
        cout<<(dp[x] >= 1e9 ? "oo" : to_string(dp[x]))<<"\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...