結果

問題 No.137 貯金箱の焦り
ユーザー pockynypockyny
提出日時 2022-12-30 14:54:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,442 ms / 5,000 ms
コード長 668 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 68,372 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 21:05:59
合計ジャッジ時間 7,871 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 15 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 4 ms
4,384 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1,442 ms
4,380 KB
testcase_13 AC 114 ms
4,380 KB
testcase_14 AC 740 ms
4,380 KB
testcase_15 AC 640 ms
4,376 KB
testcase_16 AC 608 ms
4,376 KB
testcase_17 AC 200 ms
4,380 KB
testcase_18 AC 569 ms
4,380 KB
testcase_19 AC 695 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 318 ms
4,380 KB
testcase_22 AC 39 ms
4,380 KB
testcase_23 AC 35 ms
4,376 KB
testcase_24 AC 150 ms
4,380 KB
testcase_25 AC 419 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
typedef long long ll;
ll mod = 1234567891,dp[200010],a[110];
int main(){
    ll i,j,n,m; cin >> n >> m;
    for(i=0;i<n;i++) cin >> a[i];
    dp[0] = 1;
    int sum = 0;
    for(i=0;i<n;i++) sum += a[i];
    while(m){
        for(i=0;i<n;i++){
            for(j=2*sum;j>=a[i];j--){
                (dp[j] += dp[j - a[i]]) %= mod;
            }
        }
        for(j=0;j<=2*sum;j++){
            ll nx = 2*j + (m&1);
            if(nx<=2*sum) dp[j] = dp[nx];
            else dp[j] = 0;
        }
        m /= 2;
        // for(j=0;j<=sum;j++) cout << dp[j] << " ";
        // cout << "\n";
    }
    cout << dp[0] << "\n";
}
0