結果
問題 |
No.2866 yuusaan's Knapsack
|
ユーザー |
|
提出日時 | 2024-10-19 02:03:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,045 bytes |
コンパイル時間 | 2,105 ms |
コンパイル使用メモリ | 198,504 KB |
最終ジャッジ日時 | 2025-02-24 21:24:51 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; #include<atcoder/modint> using namespace atcoder; using mint=modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll N,W; cin>>N>>W; vector<pair<ll,mint>> DP(30010,{-1e18,0}); DP[10000]={0,1}; for(int i=0;i<N;i++){ ll u,v; cin>>v>>u; auto NDP=DP; for(int w=0;w<30010;w++){ if(w+u<30010&&w+u>=0){ if(NDP[w+u].first==DP[w].first+v){ NDP[w+u].second+=DP[w].second; } else if(NDP[w+u].first<DP[w].first+v){ NDP[w+u]={DP[w].first+v,DP[w].second}; } else{ } } } swap(DP,NDP); } ll mx=-1e18; mint an=0; for(int w=10000+W;w>=0;w--){ if(mx<DP[w].first){ an=0; mx=DP[w].first; } if(mx==DP[w].first)an+=DP[w].second; } cout<<mx<<" "<<an.val()<<endl; }