This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e7 + 5;
vector<int> dp(maxn, 1e9);
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> p(n);
for(int &x : p) cin >> x;
dp[0] = 0;
for(int i=1; i<=1000; i++) {
for(int &x : p) {
if(i % x == 0) continue;
dp[i] = min(dp[i], dp[(i/x)*x] + 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... |