結果
問題 | 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 sys 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()) S = S() N = len(S) count = [0]*26 for s in S: count[ord(s)-65] += 1 def order(n,p): res = 0 while n % p == 0: res += 1 n //= p return res,n order3,order191 = 0,0 mod3,mod191 = 1,1 for i in range(1,N+1): e3,f3 = order(i,3) e191,f191 = order(i,191) order3 += e3 mod3 *= f3 mod3 %= 3 order191 += e191 mod191 *= f191 mod191 %= 191 for c in count: for i in range(1,c+1): e3,f3 = order(i,3) e191,f191 = order(i,191) order3 -= e3 mod3 *= f3 mod3 %= 3 order191 -= e191 mod191 *= pow(f191,189,191) mod191 %= 191 if order3: mod3 = 0 if order191: mod191 = 0 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 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 ans,l = remainder([(mod3,3),(mod191,191)]) ans -= 1 ans %= 573 print(ans)