結果

問題 No.137 貯金箱の焦り
ユーザー Yifan KangYifan Kang
提出日時 2023-05-01 03:58:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 865 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 168,424 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 11:47:54
合計ジャッジ時間 3,467 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 169 ms
6,940 KB
testcase_13 AC 14 ms
6,944 KB
testcase_14 AC 78 ms
6,940 KB
testcase_15 AC 69 ms
6,944 KB
testcase_16 AC 65 ms
6,940 KB
testcase_17 AC 23 ms
6,940 KB
testcase_18 AC 62 ms
6,940 KB
testcase_19 AC 73 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 35 ms
6,940 KB
testcase_22 AC 6 ms
6,944 KB
testcase_23 AC 5 ms
6,944 KB
testcase_24 AC 17 ms
6,940 KB
testcase_25 AC 44 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define ll long long
using namespace std;
const int N = 2e5 + 5,P = 1234567891;
int sum[105],a[105],n;
ll dp[N];
ll m;
void upd(ll &x,const ll y){x = (x + y) % P;}
int main(){
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    rep(i,1,n)cin >> a[i];
    rep(i,1,n)sum[i] = sum[i - 1] + a[i];
    dp[0] = 1;
    while(m){
        rep(i,sum[n],2 * sum[n] + 5)dp[i] = 0;
        rep(i,1,n)per(k,sum[n] + sum[i],a[i]){
            upd(dp[k],dp[k - a[i]]);
        }
        rep(k,0,sum[n])dp[k] = dp[2 * k + m % 2];
        m /= 2;
    }
    cout << dp[0] << endl;
    return 0;
}
0