結果

問題 No.137 貯金箱の焦り
ユーザー HIR180HIR180
提出日時 2020-04-19 12:39:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 886 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 195,328 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-15 09:28:31
合計ジャッジ時間 3,580 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 8 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 6 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 130 ms
9,600 KB
testcase_13 AC 71 ms
7,296 KB
testcase_14 AC 63 ms
6,912 KB
testcase_15 AC 56 ms
6,784 KB
testcase_16 AC 52 ms
6,656 KB
testcase_17 AC 21 ms
5,376 KB
testcase_18 AC 51 ms
6,656 KB
testcase_19 AC 59 ms
6,656 KB
testcase_20 AC 5 ms
5,376 KB
testcase_21 AC 30 ms
6,016 KB
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 8 ms
5,376 KB
testcase_24 AC 17 ms
5,376 KB
testcase_25 AC 37 ms
5,888 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;
	int c = 0;
	rep(i, 60){
	    memset(tmp, 0, sizeof(tmp));
	    memcpy(tmp, *(dp+i), sizeof(*(dp+i)));
	    rep(j, n){
	        for(int k=c;k>=0;k--) add(tmp[k+a[j]], tmp[k]);
	        c += a[j];
	    }
		int f = ((m>>i)&1);
		rep(j, c+1){
		    if(f != (j&1)) continue;
			add(dp[i+1][j/2], tmp[j]);
		}
		c /= 2;
	}
	cout << dp[60][0] << '\n';
}
0