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