結果

問題 No.695 square1001 and Permutation 4
ユーザー square1001square1001
提出日時 2018-05-12 21:44:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 791 bytes
コンパイル時間 561 ms
コンパイル使用メモリ 63,916 KB
実行使用メモリ 81,808 KB
最終ジャッジ日時 2023-09-30 01:16:43
合計ジャッジ時間 3,629 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 23 ms
7,420 KB
testcase_02 AC 30 ms
23,908 KB
testcase_03 AC 29 ms
23,780 KB
testcase_04 AC 104 ms
23,780 KB
testcase_05 AC 109 ms
23,872 KB
testcase_06 AC 246 ms
44,324 KB
testcase_07 AC 207 ms
44,328 KB
testcase_08 AC 175 ms
44,516 KB
testcase_09 AC 201 ms
44,256 KB
testcase_10 AC 51 ms
11,532 KB
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
int n, m, x[7], dp[20000009];
int solve(int mod) {
	dp[0] = 1;
	for (int i = 1; i <= 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;
			}
		}
	}
	return dp[n];
}
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; n--;
	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