This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll N=12e6+5;
const ll INF=1e9+1;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define lwb lower_bound
ll m,q,x,jump[N],dp[N];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>m>>q;
REP(i,m){
cin>>x;
for(int j=x-1;j<N;j+=x){
jump[j]=x-1;
}
}
for(int i=N-2;i>=1;i--){
jump[i]=max(jump[i],jump[i+1]-1);
}
for(int i=1;i<N;i++){
if(jump[i]==0)dp[i]=INF;
else dp[i]=min(dp[i-jump[i]]+1,INF);
}
while(q--){
cin>>x;
if(dp[x]>x){
cout<<"oo\n";
}else{
cout<<dp[x]<<"\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |