結果
問題 |
No.2370 He ate many cakes
|
ユーザー |
👑 ![]() |
提出日時 | 2023-07-03 21:10:18 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 313 ms / 2,000 ms |
コード長 | 793 bytes |
コンパイル時間 | 2,863 ms |
コンパイル使用メモリ | 255,080 KB |
実行使用メモリ | 79,484 KB |
最終ジャッジ日時 | 2024-07-17 19:06:00 |
合計ジャッジ時間 | 5,809 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, K; cin >> N >> K; vector<ll> A(N); ll max = 0; for(ll& a : A) { cin >> a; if(a >= 0) max += a; else a = -a; } static bitset<1 << 30> used; priority_queue q(greater<>{}, vector<pair<ll, int>>{}); auto push = [&](int bit, ll cost) { if(used[bit]) return; used[bit] = 1; q.emplace(cost, bit); }; push(0, 0); while(1) { auto [c, bit] = q.top(); q.pop(); if(--K == 0) { cout << max - c << endl; return 0; } for(int i = 0; i < N; i++) if(~bit & 1 << i) push(bit | 1 << i, c + A[i]); } }