이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define pii pair<int, int>
using namespace std;
const int mxN = 2e7;
const int mod = 1e9 + 7;
int m, Q, dp[mxN];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("Bai3.inp", "r", stdin);
//freopen("Bai3.out", "w", stdout);
cin >> m >> Q;
for(int i = 1; i <= m; ++i){
int p; cin >> p;
for(int j = p - 1; j < mxN; j += p){
dp[j] = max(dp[j], p - 1);
}
}
for(int i = mxN - 2; i >= 0; --i){
dp[i] = max(dp[i], dp[i + 1] - 1);
}
dp[0] = 0;
for(int i = 1; i < mxN; ++i){
if(dp[i] > 0){
dp[i] = 1 + dp[i - dp[i]];
}
else{
dp[i] = mod;
}
}
while(Q--){
int x; cin >> x;
if(dp[x] >= mxN) 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... |