結果
問題 | No.171 スワップ文字列(Med) |
ユーザー |
![]() |
提出日時 | 2021-08-31 00:55:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 45 ms / 1,000 ms |
コード長 | 1,551 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 60,672 KB |
最終ジャッジ日時 | 2024-11-24 11:14:19 |
合計ジャッジ時間 | 1,502 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
import sysdef 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())S = S()N = len(S)count = [0]*26for s in S:count[ord(s)-65] += 1def order(n,p):res = 0while n % p == 0:res += 1n //= preturn res,norder3,order191 = 0,0mod3,mod191 = 1,1for i in range(1,N+1):e3,f3 = order(i,3)e191,f191 = order(i,191)order3 += e3mod3 *= f3mod3 %= 3order191 += e191mod191 *= f191mod191 %= 191for c in count:for i in range(1,c+1):e3,f3 = order(i,3)e191,f191 = order(i,191)order3 -= e3mod3 *= f3mod3 %= 3order191 -= e191mod191 *= pow(f191,189,191)mod191 %= 191if order3:mod3 = 0if order191:mod191 = 0def ext_gcd(a,b): # a*x+b*y == gcd(a,b) たる gcd(a,b),x,yif b > 0:d,x,y = ext_gcd(b,a % b)return d,y,x-(a//b)*yreturn a,1,0def remainder(V): # Z == Xi (mod Yi) たる Z, lcm(Yi)x,lcm = 0,1for X,Y in V:g,a,b = ext_gcd(lcm,Y)x,lcm = (Y*b*x+lcm*a*X)//g,lcm*(Y//g)x %= lcmreturn x,lcmans,l = remainder([(mod3,3),(mod191,191)])ans -= 1ans %= 573print(ans)