이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int ma[100001];
int dp[10000001];
vector<int> fac[10000001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,s;
cin>>n>>s;
int aa;
dp[1]=1;
dp[0]=0;
priority_queue<pair<int,int>> ac;
int it[n];
for(int i=0;i<n;i++){
cin>>it[i];
ac.push({1,i});
ma[i]=1;
}
for(int i=0;i<n;i++){
for(int j=it[i];j<10000001;j+=it[i]){
fac[j].pb(i);
}
}
int co=1;
for(int j=2;j<10000001;j++){
for(auto k:fac[j]){
ma[k]=-co;
ac.push({-co,k});
}
int prev=j;
while(ac.size()){
pair<int,int> x=ac.top();
if(ma[x.b]!=x.a){
ac.pop();
continue;
}
prev=j-(x.a+co);
break;
}
if(prev==j){
dp[j]=-1;
}
else if(dp[prev]!=-1){
dp[j]=dp[prev]+1;
}
else{
dp[j]=-1;
}
co+=1;
}
while(s--){
cin>>aa;
if(dp[aa]==-1){
cout<<"oo"<<endl;
}
else{
cout<<dp[aa]<<endl;
}
}
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... |