結果
問題 | No.695 square1001 and Permutation 4 |
ユーザー |
![]() |
提出日時 | 2018-05-13 10:33:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,129 ms / 7,000 ms |
コード長 | 990 bytes |
コンパイル時間 | 621 ms |
コンパイル使用メモリ | 66,004 KB |
実行使用メモリ | 42,652 KB |
最終ジャッジ日時 | 2024-07-22 19:13:31 |
合計ジャッジ時間 | 5,098 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 12 |
ソースコード
#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;}