結果
問題 | No.1821 LEQ-GEQ Permutations |
ユーザー | nok0 |
提出日時 | 2022-01-16 22:35:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,230 ms / 2,500 ms |
コード長 | 1,237 bytes |
コンパイル時間 | 406 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 275,056 KB |
最終ジャッジ日時 | 2024-05-02 18:45:16 |
合計ジャッジ時間 | 20,803 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
67,072 KB |
testcase_01 | AC | 48 ms
66,816 KB |
testcase_02 | AC | 50 ms
67,200 KB |
testcase_03 | AC | 51 ms
66,688 KB |
testcase_04 | AC | 51 ms
66,560 KB |
testcase_05 | AC | 47 ms
66,816 KB |
testcase_06 | AC | 48 ms
66,688 KB |
testcase_07 | AC | 103 ms
85,632 KB |
testcase_08 | AC | 182 ms
92,032 KB |
testcase_09 | AC | 1,490 ms
214,456 KB |
testcase_10 | AC | 90 ms
83,840 KB |
testcase_11 | AC | 198 ms
94,080 KB |
testcase_12 | AC | 186 ms
92,288 KB |
testcase_13 | AC | 326 ms
103,844 KB |
testcase_14 | AC | 649 ms
137,536 KB |
testcase_15 | AC | 1,346 ms
202,300 KB |
testcase_16 | AC | 1,281 ms
197,064 KB |
testcase_17 | AC | 626 ms
133,052 KB |
testcase_18 | AC | 2,230 ms
274,932 KB |
testcase_19 | AC | 2,192 ms
275,056 KB |
testcase_20 | AC | 2,181 ms
274,928 KB |
testcase_21 | AC | 2,180 ms
274,924 KB |
testcase_22 | AC | 2,220 ms
274,668 KB |
testcase_23 | AC | 803 ms
274,204 KB |
testcase_24 | AC | 790 ms
274,288 KB |
ソースコード
mod = 998244353 table_len = 10 ** 5 + 10 fac = [1, 1] for i in range(2, table_len): fac.append(fac[-1] * i % mod) finv = [0] * table_len finv[-1] = pow(fac[-1], mod - 2, mod) for i in range(table_len - 1, 0, -1): finv[i - 1] = finv[i] * i % mod def comb(n, k): if k < 0 or n < 0 or n - k < 0: return 0 return fac[n] * finv[k] % mod * finv[n - k] % mod n = int(input()) s = input() c0 = s.count('0') c1 = n - c0 dp = [[0] * (n + 1) for i in range(n + 1)] dp[0][0] = 1 for i in range(n): for j in range(n + 1): if i + 2 <= n and j + 1 <= n: dp[i + 2][j + 1] = (dp[i + 2][j + 1] + dp[i][j] * (i + 1)) % mod if j + 1 <= n: dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * (i - j)) % mod dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] * j) % mod res = 0 for eq0 in range(c0 + 1): for eq1 in range(c1 + 1): pos_eq = comb(c0, eq0) * comb(c1, eq1) * fac[eq0] * fac[eq1] % mod num_eq = comb(c0 + c1, eq0) * comb(c0 + c1 - eq0, eq1) % mod pos_neq = dp[c0 - eq0 + c1 - eq1][c0 - eq0] pos_neq2 = fac[c0 - eq0] * fac[c1 - eq1] % mod res += pos_eq * num_eq % mod * pos_neq % mod * pos_neq2 % mod res %= mod print(res)