# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
925378 | 8pete8 | Brunhilda’s Birthday (BOI13_brunhilda) | C++17 | 204 ms | 80064 KiB |
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<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<cassert>
#include<limits.h>
#include<cmath>
#include<set>
#include<numeric> //gcd(a,b)
#include<algorithm>
#include<bitset>
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
//#define int long long
const int mod=1e9+7,mxn=1e7+100000,lg=30;//inf=1e18,minf=-1e18,Mxn=100000,root=700;
void setIO(string name){
ios_base::sync_with_stdio(0); cin.tie(0);
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
int n,q;
int ans[mxn+10],mx[mxn+10];
int32_t main(){
//setIO("redistricting");
fastio
cin>>n>>q;
vector<int>v(n);
for(int i=0;i<n;i++)cin>>v[i];
sort(all(v));
v.erase(unique(all(v)),v.end());
for(auto i:v)for(int j=i-1;j<=mxn;j+=i)mx[j]=max(mx[j],i-1);
for(int i=mxn;i>=0;i--)mx[i]=max(mx[i],mx[i+1]-1);
for(int i=1;i<=mxn;i++){
ans[i]=ans[i-mx[i]];
if(ans[i]!=-1)ans[i]++;
if(mx[i]<=0)ans[i]=-1;
}
while(q--){
int g;cin>>g;
if(ans[g]!=-1)cout<<ans[g]<<'\n';
else cout<<"oo"<<'\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |