# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1109599 | 2024-11-07T06:49:36 Z | 0pt1mus23 | Brunhilda’s Birthday (BOI13_brunhilda) | C++14 | 0 ms | 0 KB |
#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]; vector<pair<int,int>> event[sze]; void fast(){ for(int i=1;i<sze;i++){ dp[i]=inf; } int n,q; cin>>n>>q; multiset<int> ans; int mx = 0; for(int i=1;i<=n;i++){ int p;cin>>p; event[p].pb({p,p}); mx=max(mx,p); } for(int i =1;i<sze;i++){ for(auto v:event[i]){ if(ans.find(dp[v.first]) !=ans.end() ){ ans.erase(ans.find(dp[v.first])); } } if( ans.empty() ){ if(i < mx){ dp[i]=1; } } else{ dp[i]= (*ans.begin())+1; } if(dp[i]<inf){ for(auto v:event[i]){ ans.ins(dp[i]) event[i + v.second].pb({i,v.second}); } } } 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; }