Submission #283050

#TimeUsernameProblemLanguageResultExecution timeMemory
283050egekabasBrunhilda’s Birthday (BOI13_brunhilda)C++14
8.10 / 100
118 ms41720 KiB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n, q;
int p[100009];
int ans[10000001];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> q;
    for(int i = 0; i < n; ++i)
        cin >> p[i];
    reverse(p, p+n);
    ans[0] = 0;
    int lim = 1e7+1;
    for(int i = 1; i < lim; ++i){
        for(int j = 0; j <= n; ++j){
            if(j == n){
                lim = i;
                break;
            }
            if(i%p[j] != 0){
                ans[i] = 1+ans[i-i%p[j]];
                break;
            }
        }
    }
    while(q--){
        int x;
        cin >> x;
        if(x >= lim)
            cout << "oo\n";
        else
            cout << ans[x] << '\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...