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 pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
//#define int long long int
using namespace std;
int dp[10000001];
int f[10000001][8];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m, q;
cin >> m >> q;
set<ii> ptr;
vector<int> P(m);
for(int i = 0; i < m; i++){
cin >> P[i];
for(int j = P[i]; j <= 10000000; j += P[i]){
if(!f[j][0]) f[j][0] = P[i];
else if(!f[j][1]) f[j][1] = P[i];
else if(!f[j][2]) f[j][2] = P[i];
else if(!f[j][3]) f[j][3] = P[i];
else if(!f[j][4]) f[j][4] = P[i];
else if(!f[j][5]) f[j][5] = P[i];
else if(!f[j][6]) f[j][6] = P[i];
else if(!f[j][7]) f[j][7] = P[i];
else assert(0);
}
ptr.insert({0, P[i]});
}
for(int i = 1; i <= 1e7; i++) dp[i] = 1e9;
for(int i = 1; i <= 1e7; i++){
for(int j = 0; j < 8 && f[i][j]; j++){
ptr.erase({i - f[i][j], f[i][j]});
ptr.insert({i, f[i][j]});
}
if(ptr.begin()->first != i) dp[i] = dp[ptr.begin()->first] + 1;
else break;
}
while(q--){
int n;
cin >> n;
if(dp[n] >= 1e9) cout << "oo\n";
else cout << dp[n] << "\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... |