結果

問題 No.171 スワップ文字列(Med)
ユーザー ayaoniayaoni
提出日時 2020-12-28 00:58:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,888 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 56,764 KB
最終ジャッジ日時 2024-04-09 23:10:14
合計ジャッジ時間 1,597 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,700 KB
testcase_01 AC 40 ms
54,848 KB
testcase_02 AC 43 ms
54,564 KB
testcase_03 AC 43 ms
55,896 KB
testcase_04 AC 39 ms
54,716 KB
testcase_05 AC 40 ms
55,724 KB
testcase_06 WA -
testcase_07 AC 40 ms
54,436 KB
testcase_08 AC 41 ms
55,400 KB
testcase_09 AC 40 ms
56,140 KB
testcase_10 AC 40 ms
54,544 KB
testcase_11 AC 40 ms
54,232 KB
testcase_12 AC 40 ms
54,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import Counter
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


def ext_gcd(a, b):  # a*x+b*y == gcd(a,b) たる gcd(a,b),x,y
    if b > 0:
        d,x,y = ext_gcd(b,a % b)
        return d,y,x-(a//b)*y
    return a,1,0


# V = [(Xi,Yi),…]

def remainder(V):  # Z == Xi (mod Yi) たる Z, lcm(Yi)
    x,lcm = 0,1
    for X,Y in V:
        g,a,b = ext_gcd(lcm,Y)
        x,lcm = (Y*b*x+lcm*a*X)//g,lcm*(Y//g)
        x %= lcm
    return x,lcm


S = S()
N = len(S)
count = Counter(S)
X = list(count.values())


def f(x):  # x!が何回3で割り切れるか
    res = 0
    while x >= 3:
        res += x//3
        x //= 3
    return res


div3 = f(N)-sum(f(x) for x in X)  # 答えが3で割れる回数
div191 = N//191-sum(x//191 for x in X)  # 答えが191で割れる回数

if div3 > 0:
    ans3 = 0
else:
    ans3 = 1
    for i in range(1,N+1):
        if i % 3 == 2:
            ans3 *= 2
            ans3 %= 3
    for x in X:
        for i in range(1,x+1):
            if i % 3 == 2:
                ans3 *= 2
                ans3 %= 3

if div191 > 0:
    ans191 = 0
else:
    ans191 = 1
    for i in range(1,N+1):
        if i % 191 != 0:
            ans191 *= i % 191
            ans191 %= 191
    a = 1
    for x in X:
        for i in range(1,x+1):
            if i % 191 != 0:
                a *= i % 191
                a %= 191
    ans191 *= pow(a,191-2,191)
    ans191 %= 191

ans,l = remainder([(ans3,3),(ans191,191)])
ans -= 1
ans %= 573
print(ans)
0