Submission #1109636

#TimeUsernameProblemLanguageResultExecution timeMemory
11096360pt1mus23Brunhilda’s Birthday (BOI13_brunhilda)C++14
20 / 100
59 ms14868 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int #define ins insert #define pb push_back #define endl '\n' #define putr(x) cout<<x<<endl;return; #define all(x) x.begin(),x.end() int nxt(){ int x;cin>>x; return x; } const int mod = 1e9 +7, sze = 1e5 +10, inf = INT_MAX, LG = 20; int dp[sze]; void fast(){ int n,q; cin>>n>>q; int mx = 0; set<pair<int,int>> var; for(int i=1;i<=n;i++){ int p;cin>>p; mx=max(mx,p); var.ins({p,p}); } for(int i=1;i<sze;i++){ dp[i]=inf; while(!var.empty()){ auto it = *var.begin(); if( it.first + it.second<=i){ // cout<<i<<" "<<it.first<<" "<<it.second<<endl; if(it.first + it.second < sze){ var.ins({it.first + it.second,it.second}); } var.erase(var.begin()); } else{ break; } } if(i<mx){ dp[i]=1; } else{ // cout<<i<<" "<<var.size()<<endl; if(!var.empty()){ auto it = *var.begin(); // cout<<i<<" "<<it.first<<endl; dp[i]= dp[it.first] +1; } } } while(q--){ int v; cin>>v; if(dp[v]>=inf){ cout<<"oo"<<endl; } else{ cout<<dp[v]<<endl; } } } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt = 1; // cin>>tt; while(tt--){ fast(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...