結果

問題 No.137 貯金箱の焦り
ユーザー HIR180HIR180
提出日時 2020-04-19 12:35:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 5,000 ms
コード長 859 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 196,136 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-04-15 09:20:36
合計ジャッジ時間 5,512 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
9,600 KB
testcase_01 AC 21 ms
9,600 KB
testcase_02 AC 27 ms
9,600 KB
testcase_03 AC 17 ms
9,692 KB
testcase_04 AC 65 ms
9,472 KB
testcase_05 AC 64 ms
9,600 KB
testcase_06 AC 65 ms
9,728 KB
testcase_07 AC 47 ms
9,728 KB
testcase_08 AC 47 ms
9,728 KB
testcase_09 AC 64 ms
9,728 KB
testcase_10 AC 44 ms
9,600 KB
testcase_11 AC 17 ms
9,472 KB
testcase_12 AC 182 ms
9,600 KB
testcase_13 AC 185 ms
9,728 KB
testcase_14 AC 183 ms
9,728 KB
testcase_15 AC 158 ms
9,728 KB
testcase_16 AC 165 ms
9,600 KB
testcase_17 AC 99 ms
9,728 KB
testcase_18 AC 155 ms
9,472 KB
testcase_19 AC 179 ms
9,600 KB
testcase_20 AC 20 ms
9,728 KB
testcase_21 AC 122 ms
9,728 KB
testcase_22 AC 47 ms
9,600 KB
testcase_23 AC 44 ms
9,600 KB
testcase_24 AC 91 ms
9,600 KB
testcase_25 AC 142 ms
9,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()
#define pb push_back
typedef pair<int,int> P;
#define fi first
#define sc second
#define mp make_pair

typedef unsigned int ui;
const ui mod = 1234567891;
ui dp[64][25005], tmp[50005], n, a[55];
long long m;

inline void add(ui &a, ui b) { a += b; if(a >= mod) a -= mod; }
int main(){
	ios::sync_with_stdio(0);
	
	cin >> n >> m;
	rep(i, n) {
	    cin >> a[i];
	}
	dp[0][0] = 1;
	rep(i, 60){
	    memset(tmp, 0, sizeof(tmp));
	    memcpy(tmp, *(dp+i), sizeof(*(dp+i)));
	    rep(j, n){
	        for(int k=50003-(int)a[j];k>=0;k--) add(tmp[k+a[j]], tmp[k]);
	    }
		int f = ((m>>i)&1);
		rep(j, 50005){
		    if(f != (j&1)) continue;
			add(dp[i+1][j/2], tmp[j]);
		}
	}
	cout << dp[60][0] << '\n';
}
0