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