提出 #28425990
ソースコード 拡げる
MOD = 998244353
N = 20000
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
fact[i] = fact[i - 1] * i % MOD
invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)
for i in range(N - 2, -1, -1):
invfact[i] = invfact[i + 1] * (i + 1) % MOD
def nCk(n, k):
if k < 0 or n < k:
return 0
else:
return (fact[n] * invfact[k] % MOD) * invfact[n - k] % MOD
S = input()
len_s = len(S)
cnt = [0]*26
for s in S:
cnt[ord(s) - 97] += 1
dp = [[0] * (len_s + 1) for _ in range(27)]
dp[0][0] = 1
for i, c in enumerate(cnt, 1):
for j in range(len_s+1):
for k in range(c+1):
if dp[i-1][j] == 0:
break
dp[i][j+k] += dp[i-1][j]*nCk(j+k, k)
dp[i][j+k] %= MOD
print((sum(dp[-1]) - 1) % MOD)
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Reordering |
| ユーザ | kkp |
| 言語 | PyPy3 (7.3.0) |
| 得点 | 500 |
| コード長 | 846 Byte |
| 結果 | AC |
| 実行時間 | 343 ms |
| メモリ | 76340 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, example0.txt, example1.txt, example2.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 241 ms | 75676 KiB |
| 001.txt | AC | 221 ms | 75748 KiB |
| 002.txt | AC | 221 ms | 75708 KiB |
| 003.txt | AC | 222 ms | 75756 KiB |
| 004.txt | AC | 62 ms | 68260 KiB |
| 005.txt | AC | 59 ms | 68492 KiB |
| 006.txt | AC | 74 ms | 74720 KiB |
| 007.txt | AC | 219 ms | 75680 KiB |
| 008.txt | AC | 79 ms | 74768 KiB |
| 009.txt | AC | 163 ms | 75868 KiB |
| 010.txt | AC | 84 ms | 75312 KiB |
| 011.txt | AC | 134 ms | 75496 KiB |
| 012.txt | AC | 175 ms | 75692 KiB |
| 013.txt | AC | 96 ms | 75336 KiB |
| 014.txt | AC | 85 ms | 75432 KiB |
| 015.txt | AC | 73 ms | 74716 KiB |
| 016.txt | AC | 164 ms | 75680 KiB |
| 017.txt | AC | 124 ms | 75360 KiB |
| 018.txt | AC | 79 ms | 74816 KiB |
| 019.txt | AC | 161 ms | 75548 KiB |
| 020.txt | AC | 77 ms | 76040 KiB |
| 021.txt | AC | 151 ms | 75896 KiB |
| 022.txt | AC | 343 ms | 76172 KiB |
| 023.txt | AC | 212 ms | 75608 KiB |
| 024.txt | AC | 222 ms | 76004 KiB |
| 025.txt | AC | 74 ms | 76056 KiB |
| 026.txt | AC | 75 ms | 75828 KiB |
| 027.txt | AC | 267 ms | 76340 KiB |
| 028.txt | AC | 208 ms | 76112 KiB |
| 029.txt | AC | 218 ms | 75764 KiB |
| 030.txt | AC | 232 ms | 76244 KiB |
| 031.txt | AC | 78 ms | 75908 KiB |
| example0.txt | AC | 58 ms | 68676 KiB |
| example1.txt | AC | 58 ms | 68632 KiB |
| example2.txt | AC | 61 ms | 69296 KiB |