結果

問題 No.137 貯金箱の焦り
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-04 14:50:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,459 ms / 5,000 ms
コード長 587 bytes
コンパイル時間 1,308 ms
コンパイル使用メモリ 159,616 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 11:52:31
合計ジャッジ時間 18,819 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
5,248 KB
testcase_01 AC 65 ms
5,376 KB
testcase_02 AC 123 ms
5,376 KB
testcase_03 AC 35 ms
5,376 KB
testcase_04 AC 440 ms
5,376 KB
testcase_05 AC 434 ms
5,376 KB
testcase_06 AC 438 ms
5,376 KB
testcase_07 AC 295 ms
5,376 KB
testcase_08 AC 294 ms
5,376 KB
testcase_09 AC 440 ms
5,376 KB
testcase_10 AC 266 ms
5,376 KB
testcase_11 AC 35 ms
5,376 KB
testcase_12 AC 1,452 ms
5,376 KB
testcase_13 AC 1,459 ms
5,376 KB
testcase_14 AC 1,443 ms
5,376 KB
testcase_15 AC 1,244 ms
5,376 KB
testcase_16 AC 1,292 ms
5,376 KB
testcase_17 AC 754 ms
5,376 KB
testcase_18 AC 1,206 ms
5,376 KB
testcase_19 AC 1,400 ms
5,376 KB
testcase_20 AC 65 ms
5,376 KB
testcase_21 AC 918 ms
5,376 KB
testcase_22 AC 298 ms
5,376 KB
testcase_23 AC 266 ms
5,376 KB
testcase_24 AC 675 ms
5,376 KB
testcase_25 AC 1,099 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define MAX 52000

long long dp[MAX];

long long mod = 1234567891;

int main() {
	int N;
	long long M;
	cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	dp[0] = 1;
	for (int t = 60; t >= 0; t--)
	{
		int add = (M >> t) % 2;
		for (int i = MAX - 1; i >= 0; i--)
		{
			if (i % 2 == add) dp[i] = dp[i / 2];
			else dp[i] = 0;
		}
		for (int i = 0; i < N; i++)
		{
			for (int j = A[i]; j < MAX; j++)
			{
				dp[j - A[i]] += dp[j];
				dp[j - A[i]] %= mod;
			}
		}
	}
	cout << dp[0] << endl;
	cin >> N;
}
0