結果

問題 No.2866 yuusaan's Knapsack
ユーザー NachiaNachia
提出日時 2024-08-30 21:44:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,539 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 80,916 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-31 01:27:19
合計ジャッジ時間 1,733 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 6 ms
6,940 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 6 ms
6,944 KB
testcase_16 AC 5 ms
6,940 KB
testcase_17 AC 6 ms
6,944 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 AC 6 ms
6,944 KB
testcase_20 AC 5 ms
6,940 KB
testcase_21 AC 5 ms
6,944 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 6 ms
6,940 KB
testcase_24 AC 5 ms
6,940 KB
testcase_25 AC 6 ms
6,940 KB
testcase_26 AC 5 ms
6,940 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
#include <atcoder/modint>
using Modint = atcoder::static_modint<998244353>;
using namespace std;

void testcase(){
    i64 N, W; cin >> N >> W;
    i64 Z = 20010;
    vector<pair<i64,Modint>> dpc(Z, {-INF, 0});
    i64 s = 10003;
    dpc[s] = {0,1};
    auto add = [&](pair<i64,Modint>& l, pair<i64,Modint> r, i64 v){
        r.first += v;
        if(l.first < r.first){ l = r; }
        else if(l.first == r.first){ l.second += r.second; }
    };
    i64 minsum = 0;
    rep(i,N){
        i64 v,w; cin >> v >> w;
        if(w < 0){
            for(i64 p=0; p-w<Z; p++) add(dpc[p], dpc[p-w], v);
            minsum += w;
        } else if(w == 0) {
            for(i64 p=0; p<Z; p++) add(dpc[p], dpc[p], v);
        } else {
            for(i64 p=Z-1; p-w>=0; p--) add(dpc[p], dpc[p-w], v);
        }
    }
    if(minsum > W){
        exit(1);
        return;
    }
    pair<i64, Modint> ans = {-INF, 0};
    rep(i,Z) if(i - s <= W) add(ans, dpc[i], 0);
    cout << ans.first << ' ';
    cout << ans.second.val() << endl;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}
0