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 ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n, q;
int p[100009];
int ans[10000001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
srand(time(NULL));
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n >> q;
for(int i = 0; i < n; ++i)
cin >> p[i];
reverse(p, p+n);
ans[0] = 0;
int lim = 1e7+1;
for(int i = 1; i < lim; ++i){
int goback = -1;
for(int j = 0; j < min(n, 5); ++j)
goback = max(goback, i%p[j]);
int cnt = 5;
while(cnt--){
int j = rand()%n;
goback = max(goback, i%p[j]);
}
if(goback == 0){
lim = i;
break;
}
ans[i] = 1+ans[i-goback];
}
while(q--){
int x;
cin >> x;
if(x >= lim)
cout << "oo\n";
else
cout << ans[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... |