이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
using namespace std;
const int N = 1e6 + 5;
int a[100003],inf=1e9;
signed main(){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,q;
cin>>n>>q;
int m = 10000000;
vector <int> prv(m + 1),dp(m + 1);
for (int i = 1;i <= n; i++){
cin >> a[i];
for (int j = a[i] - 1; j <= m; j += a[i])
prv[j] = max(prv[j],a[i] - 1);
}
for (int i=m;i>=1;i--){
prv[i]=max(prv[i],prv[i + 1] - 1);
}
dp[0] = 0;
for (int i = 1;i <= m; i++){
dp[i] = inf;
if (i >= prv[i])
dp[i] = min(dp[i],dp[i - prv[i]] + 1);
}
while (q--){
int x;
cin>>x;
if (dp[x] == 1e9) cout<<"oo"<<endl;
else cout<<dp[x]<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |