結果

問題 No.171 スワップ文字列(Med)
ユーザー tktk_snsntktk_snsn
提出日時 2021-02-27 00:44:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 204 ms / 1,000 ms
コード長 909 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2024-04-10 14:57:39
合計ジャッジ時間 4,084 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 195 ms
19,968 KB
testcase_01 AC 200 ms
19,840 KB
testcase_02 AC 204 ms
19,840 KB
testcase_03 AC 202 ms
19,840 KB
testcase_04 AC 200 ms
19,968 KB
testcase_05 AC 199 ms
19,968 KB
testcase_06 AC 200 ms
19,840 KB
testcase_07 AC 201 ms
19,968 KB
testcase_08 AC 198 ms
19,840 KB
testcase_09 AC 201 ms
19,968 KB
testcase_10 AC 204 ms
19,968 KB
testcase_11 AC 203 ms
19,840 KB
testcase_12 AC 201 ms
19,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
mod = 573


class PascalsTriangle:
    def __init__(self, N, mod):
        self.N = N
        self.mod = mod
        self._build()

    def __call__(self, n, r):
        if n > self.N:
            raise "INVALID INPUT: input n must be smaller than N"
        if r < 0 or r > self.N:
            return 0
        return self.nCr[n][r]

    def _build(self):
        tmp = [(1,)]
        P = self.mod
        for i in range(1, self.N + 1):
            nCi = tuple(1 if j in (0, i)
                        else (tmp[-1][j-1] + tmp[-1][j]) % P for j in range(i+1))
            tmp.append(nCi)
        self.nCr = tuple(tmp)


def main():
    S = input()
    C = Counter(S)

    pc = PascalsTriangle(1000, mod)
    N = len(S)
    ans = 1
    for v in C.values():
        ans *= pc(N, v)
        ans %= mod
        N -= v
    ans = (ans + mod - 1) % mod
    return ans


print(main())
0