이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// NgJaBach: Forever Meadow <3
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef unsigned long long ull;
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define bend(a) a.begin(),a.end()
#define rev(x) reverse(bend(x))
#define mset(a) memset(a, 0, sizeof(a))
#define fi first
#define se second
#define gcd __gcd
#define getl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
#define endl '\n'
const int N=12000000,M=1000000000;
const ll INF=1e18+7;
int dp[N+50];
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
// freopen(".inp","r",stdin);
// freopen(".out","w",stdout);
int n,q,a;
cin>>n>>q;
mset(dp);
while(n--){
cin>>a;
for(int i=a-1;i<=N;i+=a) dp[i]=max(dp[i],a-1);
}
for(int i=N;i>0;--i) dp[i]=max(dp[i],dp[i+1]-1);
for(int i=1;i<=N;++i){
if(dp[i]>0) dp[i]=dp[i-dp[i]]+1;
else dp[i]=M;
}
while(q--){
cin>>a;
if(dp[a]>=M) cout<<"oo";
else cout<<dp[a];
cout<<endl;
}
return 0;
}
/*
==================================+
INPUT: |
------------------------------ |
2 2
2 3
5
6
------------------------------ |
==================================+
OUTPUT: |
------------------------------ |
------------------------------ |
==================================+
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |