結果
問題 |
No.2370 He ate many cakes
|
ユーザー |
|
提出日時 | 2023-07-04 19:06:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 1,531 bytes |
コンパイル時間 | 1,081 ms |
コンパイル使用メモリ | 100,240 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-18 14:19:54 |
合計ジャッジ時間 | 2,151 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:67:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 67 | auto [v,i,j]=pq.top(); | ^
ソースコード
#include<iostream> #include<set> #include<algorithm> #include<vector> #include<string> #include<set> #include<map> #include<numeric> #include<queue> #include<cmath> using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair<int,int> P; typedef pair<int,P> PP; const ll MOD=1e9+7; int main(){ int N; ll K; cin>>N>>K; vector<ll> A(N); for(int i=0;i<N;i++){ cin>>A[i]; } int n=N/2; vector<ll> arrayC,arrayD; for(int S=0;S<(1<<n);S++){ ll sum=0; for(int i=0;i<n;i++){ if((S>>i)&1){ sum+=A[i]; } } arrayC.push_back(sum); } for(int S=0;S<(1<<(N-n));S++){ ll sum=0; for(int i=0;i<(N-n);i++){ if((S>>i)&1){ sum+=A[i+n]; } } arrayD.push_back(sum); } //arrayD.push_back(0); sort(arrayD.begin(),arrayD.end()); reverse(arrayD.begin(),arrayD.end());//大きいほうから取り出す typedef tuple<ll,int,ll> TP; priority_queue<TP,vector<TP>,greater<TP>> pq; for(int i=0;i<arrayC.size();i++){ pq.push(make_tuple(-(arrayC[i]+arrayD[0]),i,0)); } ll cnt=0; while(1){ auto [v,i,j]=pq.top(); pq.pop(); cnt++; //cout<<"v="<<-v<<endl; if(cnt==K){ cout<<-v<<endl; return 0; } if(j+1<arrayD.size()){ pq.emplace( -(arrayC[i]+arrayD[j+1]),i,j+1) ; } } }