結果

問題 No.2370 He ate many cakes
ユーザー HIcoderHIcoder
提出日時 2023-07-04 19:06:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,531 bytes
コンパイル時間 1,157 ms
コンパイル使用メモリ 98,100 KB
実行使用メモリ 4,676 KB
最終ジャッジ日時 2023-09-25 18:06:00
合計ジャッジ時間 2,509 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 23 ms
4,588 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 15 ms
4,656 KB
testcase_12 AC 24 ms
4,380 KB
testcase_13 AC 38 ms
4,676 KB
testcase_14 AC 17 ms
4,588 KB
testcase_15 AC 49 ms
4,608 KB
testcase_16 AC 45 ms
4,380 KB
testcase_17 AC 48 ms
4,500 KB
testcase_18 AC 24 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:67:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   67 |         auto [v,i,j]=pq.top();
      |              ^

ソースコード

diff #

#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) ;
        }
    }





}
0