Submission #378496

#TimeUsernameProblemLanguageResultExecution timeMemory
378496YJUBrunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
449 ms189292 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector,Ofast") using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const ll N=12e6+5; const ll INF=1e9+1; #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define X first #define Y second #define pb push_back #define mp make_pair #define lwb lower_bound ll m,q,x,jump[N],dp[N]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>m>>q; REP(i,m){ cin>>x; for(int j=x-1;j<N;j+=x){ jump[j]=x-1; } } for(int i=N-2;i>=1;i--){ jump[i]=max(jump[i],jump[i+1]-1); } for(int i=1;i<N;i++){ if(jump[i]==0)dp[i]=INF; else dp[i]=min(dp[i-jump[i]]+1,INF); } while(q--){ cin>>x; if(dp[x]>x){ cout<<"oo\n"; }else{ cout<<dp[x]<<"\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...