結果
| 問題 | No.171 スワップ文字列(Med) |
| コンテスト | |
| ユーザー |
ayaoni
|
| 提出日時 | 2020-12-27 21:16:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,824 bytes |
| 記録 | |
| コンパイル時間 | 483 ms |
| コンパイル使用メモリ | 82,388 KB |
| 実行使用メモリ | 56,212 KB |
| 最終ジャッジ日時 | 2024-10-01 20:32:36 |
| 合計ジャッジ時間 | 1,523 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 2 |
ソースコード
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 factorial(N,p): # 0!~N!(mod p) のリスト
res = [0]*(N+1)
res[0] = 1
for i in range(1,N+1):
res[i] = (res[i-1]*i) % p
return res
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())
fac191 = factorial(190,191)
def f(x): # x!が何回3で割り切れるか
res = 0
while x >= 3:
res += x//3
x //= 3
return res
r = f(N)
ans3 = pow(2,N//3,3)
if N % 3 == 2:
ans3 *= 2
ans3 %= 3
for x in X:
r -= f(x)
ans3 *= pow(2,x//3,3)
ans3 %= 3
if x % 3 == 2:
ans3 %= 2
ans3 %= 3
if r:
ans3 = 0
s = N//191
ans191 = 1
while N >= 191:
ans191 *= -1
ans191 %= 191
N -= 191
ans191 *= fac191[N]
ans191 %= 191
for x in X:
s -= x//191
while x >= 191:
ans191 *= -1
x -= 191
ans191 *= pow(fac191[x],189,191)
ans191 %= 191
if s:
ans191 = 0
ans,l = remainder([(ans3,3),(ans191,191)])
ans -= 1
ans %= 573
print(ans)
ayaoni