Submission #553679

#TimeUsernameProblemLanguageResultExecution timeMemory
553679new_accBrunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
991 ms144468 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=1e6+10; const int SS=1<<19; const int INFi=2e9; const ll INFl=1e13; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=1000696969; const ll p=70032301; const ull p2=913; const int L=20; int dp[N*10],ile[N*10],zap[N],t[N],last[N*10]; bitset<N*10>byl; void solve(){ int n,m; cin>>m>>n; for(int i=1;i<=m;i++) cin>>t[i]; int maxi=0; for(int i=1;i<=n;i++){ cin>>zap[i]; maxi=max(maxi,zap[i]); } for(int i=1;i<=m;i++) byl[t[i]]=1; for(int i=2;i<=maxi;i++){ if(last[i]) continue; for(int j=i;j<=maxi;j+=i) last[j]=i; } deque<int> curr; curr.push_back(0); ile[0]=m; for(int i=1;i<=maxi;i++){ int xd=i,il=0,pop=0; while(xd>1){ int u=last[xd]; if(byl[u] and pop!=u) ile[((i/u)-1)*u]--,il++; pop=u; xd/=u; } while(curr.size() and !ile[curr[0]]) curr.pop_front(); if(!curr.size()) dp[i]=INFi; else dp[i]=min(dp[curr[0]]+1,INFi); curr.push_back(i); ile[i]=il; } for(int i=1;i<=n;i++){ if(dp[zap[i]]==INFi) cout<<"oo\n"; else cout<<dp[zap[i]]<<"\n"; } } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...