제출 #493670

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

#define ll long long
#define el '\n'
#define ld long double
const int maxn=1e8+1,nn=1e5+1;

int f[maxn],oo,a[nn],n,m,q,p;
int take(int z){
    if(f[z]>=0) return f[z];
    f[z]=oo;
    for(int i=0;i<m;++i) if(z%a[i]!=0) f[z]=min(f[z],take(z-z%a[i])+1);
    return f[z];
}
int main(){
    //freopen("T.INP","r",stdin);
    //freopen("T.OUT","w",stdout);
    ios_base::sync_with_stdio(0);cin.tie(0);
    memset(f,-1,sizeof f);
    oo=1e9;
    f[0]=0;
    cin >> m >> q;
    for(int i=0;i<m;++i) cin >> a[i];
    while(q--){
        cin >> n;
        p=take(n);
        if(p>=oo) cout << 'o' << 'o' << el;
        else cout << p << el;
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...