結果

問題 No.2866 yuusaan's Knapsack
ユーザー umezoumezo
提出日時 2024-08-30 22:56:18
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,312 bytes
コンパイル時間 2,829 ms
コンパイル使用メモリ 249,528 KB
実行使用メモリ 56,112 KB
最終ジャッジ日時 2024-08-31 01:29:09
合計ジャッジ時間 4,243 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
55,948 KB
testcase_01 AC 17 ms
55,872 KB
testcase_02 AC 17 ms
56,056 KB
testcase_03 AC 17 ms
55,912 KB
testcase_04 AC 17 ms
55,984 KB
testcase_05 AC 16 ms
56,076 KB
testcase_06 AC 24 ms
56,084 KB
testcase_07 AC 23 ms
55,880 KB
testcase_08 AC 24 ms
55,888 KB
testcase_09 AC 23 ms
56,020 KB
testcase_10 AC 24 ms
56,000 KB
testcase_11 AC 22 ms
55,908 KB
testcase_12 AC 23 ms
56,096 KB
testcase_13 AC 22 ms
56,008 KB
testcase_14 AC 23 ms
56,024 KB
testcase_15 AC 24 ms
55,940 KB
testcase_16 AC 22 ms
55,904 KB
testcase_17 AC 25 ms
56,048 KB
testcase_18 AC 22 ms
56,024 KB
testcase_19 AC 25 ms
55,920 KB
testcase_20 AC 24 ms
56,112 KB
testcase_21 AC 23 ms
56,108 KB
testcase_22 AC 22 ms
56,004 KB
testcase_23 AC 25 ms
56,036 KB
testcase_24 AC 22 ms
56,040 KB
testcase_25 AC 24 ms
55,944 KB
testcase_26 AC 22 ms
55,960 KB
testcase_27 AC 17 ms
56,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;

const int INF=1e9;
const int MOD=998244353;
const int geta=10000;
pair<ll,ll> dp[111][30303];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  rep(i,111) rep(j,30303) dp[i][j]={-INF,-INF};
  
  ll n,w;
  cin>>n>>w;
  V<ll> V(n),W(n);
  rep(i,n) cin>>V[i]>>W[i];
  dp[0][geta]={0,1};
  rep(i,n){
    rep(j,30303){
      if(dp[i][j].first==-INF) continue;
      
      if(dp[i+1][j].first>dp[i][j].first) ;
      else if(dp[i+1][j].first<dp[i][j].first) dp[i+1][j]=dp[i][j];
      else dp[i+1][j].second=(dp[i+1][j].second+dp[i][j].second)%MOD;
      
      if(j+W[i]>=30303) continue;
      if(dp[i+1][j+W[i]].first>dp[i][j].first+V[i]) continue;
      else if(dp[i+1][j+W[i]].first<dp[i][j].first+V[i]) dp[i+1][j+W[i]]={dp[i][j].first+V[i],dp[i][j].second};
      else dp[i+1][j+W[i]].second=(dp[i+1][j+W[i]].second+dp[i][j].second)%MOD;
    }
  }
  ll ma=-INF;
  for(int j=0;j<=geta+w;j++) ma=max(ma,dp[n][j].first);
  ll ans=0;
  for(int j=0;j<=geta+w;j++){
    if(dp[n][j].first==ma) ans=(ans+dp[n][j].second)%MOD;
  }
  cout<<ma<<" "<<ans<<endl;
 
  return 0;
}
0