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>
using namespace std;
#define SPEED ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define endl "\n"
#define ALL(X) X.begin(), X.end()
const int sz = 10005, inf = 1e9;
vector<int>dp(sz);
int f(vector<int> &a, int w) {
int t = 0;
for(int i = 0; i < (int)a.size(); i++) {
t = max(t, (w % a[i]));
}
if(t == 0) t = -1;
return t;
}
void solve() {
int m, q;
cin >> m >> q;
vector<int> a(m);
for(int i = 0; i < m; i++) cin >> a[i];
if(q == 1) {
int ans = 0;
int qq;
cin >> qq;
bool cock = false;
while(qq > 0) {
int tmp = f(a, qq);
if(tmp == -1) {
cock = true;
break;
}
qq -= tmp;
ans++;
}
if(cock) {
cout << "oo" << endl;
} else {
cout << ans << endl;
}
} else {
dp[0] = 0;
for(int i = 1; i < sz; i++) dp[i] = inf;
for(int i = 1; i < sz; i++) {
int mini = inf;
for(int j = 0; j < m; j++) {
mini = min(mini, dp[i - (i % a[j])]);
}
dp[i] = mini + 1;
}
while(q--) {
int qq;
cin >> qq;
// for(int i = 1; i <= 10; i++) {
// cout << dp[i] << " ";
// }
// cout << endl;
if(dp[qq] == inf + 1) {
cout << "oo" << endl;
} else {
cout << dp[qq] << endl;
}
}
}
}
signed main() {
SPEED;
int tst = 1;
// cin >> tst;
while(tst--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |