이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 5;
vector<int> dp(maxn, 1e9), L(maxn, 1e9);
int main() {
int n, q;
cin >> n >> q;
vector<int> p(n);
for(int &x : p) cin >> x;
L[0] = 0; dp[0] = 0;
for(int &x : p)
for(int i=0; i*x<1e7; i++) L[min((int)1e7, (i+1)*x-1)] = min(L[min((int)1e7, (i+1)*x-1)] , i * x);
for(int i=1e7-1; i>=1; i--) L[i] = min(L[i], L[i+1]);
for(int i=1; i<=1e7; i++) {
if(L[i] >= i) dp[i] = 1e9;
else dp[i] = dp[L[i]] + 1;
}
while(q--) {
int x;
cin >> x;
if(dp[x] < 1e9) cout << dp[x] << '\n';
else cout << "oo\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... |