結果

問題 No.695 square1001 and Permutation 4
ユーザー square1001square1001
提出日時 2018-05-13 10:33:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,152 ms / 7,000 ms
コード長 990 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 64,808 KB
実行使用メモリ 42,512 KB
最終ジャッジ日時 2023-09-30 01:16:59
合計ジャッジ時間 5,155 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 19 ms
5,252 KB
testcase_02 AC 22 ms
13,596 KB
testcase_03 AC 22 ms
13,660 KB
testcase_04 AC 75 ms
13,552 KB
testcase_05 AC 124 ms
13,664 KB
testcase_06 AC 162 ms
23,904 KB
testcase_07 AC 147 ms
23,984 KB
testcase_08 AC 364 ms
23,980 KB
testcase_09 AC 579 ms
23,852 KB
testcase_10 AC 34 ms
7,600 KB
testcase_11 AC 1,152 ms
42,364 KB
testcase_12 AC 844 ms
42,512 KB
testcase_13 AC 384 ms
42,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int n, m, x[7], dp[10000009];
int solve(int mod) {
	dp[0] = 1;
	for (int i = 1; 2 * i - 2 < n; i++) {
		dp[i] = 0;
		for (int j = 0; j < m; j++) {
			if (i >= x[j]) {
				dp[i] += dp[i - x[j]];
				if (dp[i] >= mod) dp[i] -= mod;
			}
		}
	}
	int ret = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; 2 * j < n; j++) {
			if (2 * (j + x[i]) >= n && j + x[i] < n) {
				ret = (ret + 1LL * dp[j] * dp[n - j - x[i] - 1]) % mod;
			}
		}
	}
	return ret;
}
int binpow(int a, int b, int mod) {
	int ret = 1;
	while (b) {
		if (b & 1) ret = 1LL * ret * a % mod;
		a = 1LL * a * a % mod;
		b >>= 1;
	}
	return ret;
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) cin >> x[i];
	int part1 = 168647939;
	int part2 = 592951213;
	int res1 = solve(part1);
	int res2 = solve(part2);
	int subans = 1LL * (res2 - res1 + part2) * binpow(part1, part2 - 2, part2) % part2;
	long long ans = 1LL * subans * part1 + res1;
	cout << ans << '\n';
	return 0;
}
0