이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=2e7+5;
int dp[nx], n, m, x, q, p, res[nx], t, cnt;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>m>>q;
for (int i=0; i<m; i++)
{
cin>>x;
for (int j=x; j<nx; j+=x) dp[j]=x;
}
for (int i=x; i<nx; i++) res[i]=-1;
for (int i=0; i<x; i++) res[i]=1;
t=1;
while (p<nx)
{
int mx=x;
t++;
for (int i=p; i<x; i++) mx=max(mx, i+dp[i]);
for (int i=x; i<min(nx-1, mx); i++) res[i]=t;
if (mx==x) break;
p=x;
x=mx;
}
//for (int i=0; i<35; i++) cout<<i<<' '<<res[i]<<'\n';
while (q--)
{
cin>>x;
if (res[x]==-1) cout<<"oo\n";
else cout<<res[x]<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |