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