結果
| 問題 |
No.3077 Goodstuff Deck Builder(Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-28 22:19:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,921 ms / 3,000 ms |
| コード長 | 1,439 bytes |
| コンパイル時間 | 2,477 ms |
| コンパイル使用メモリ | 216,484 KB |
| 実行使用メモリ | 207,944 KB |
| 最終ジャッジ日時 | 2025-03-28 22:19:50 |
| 合計ジャッジ時間 | 19,752 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 57 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long N,M; cin >> N >> M;
vector<pair<long long,long long>> CD(N);
for(auto &[c,d] : CD) cin >> c >> d;
sort(CD.rbegin(),CD.rend());
long long add = 0;
while(CD.size()){
auto [c,d] = CD.back();
if(c == 0) add += d,CD.pop_back();
else break;
}
if(24*M >= 50000000){
vector<map<int,long long>> dp(24);
dp.at(0)[0] = 0;
for(auto [c,d] : CD){
c <<= 22;
for(int i=22; i>=0; i--,c>>=1) for(auto [k,v] : dp.at(i)){
if(k+c > M) break;
dp.at(i+1)[k+c] = max(dp.at(i+1)[k+c],dp.at(i).at(k)+d);
}
}
long long ans = 0;
for(auto &M : dp) for(auto [k,v] : M) ans = max(ans,v);
ans += add;
cout << ans << endl; return 0;
}
long long inf = 1e18;
vector dp(24,vector(M+1,-inf));
dp.at(0).at(0) = 0;
for(auto [c,d] : CD){
c <<= 22;
for(long long i=22; i>=0; i--,c>>=1) for(long long k=0; ; k++){
if(k+c > M) break;
if(dp.at(i).at(k) == inf) continue;
dp.at(i+1).at(k+c) = max(dp.at(i+1).at(k+c),dp.at(i).at(k)+d);
}
}
long long answer = 0;
for(auto &d : dp) for(auto v : d) answer = max(answer,v);
answer += add;
cout << answer << endl;
}