結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー 👑 timitimi
提出日時 2023-06-22 17:14:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 941 bytes
コンパイル時間 447 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 92,428 KB
最終ジャッジ日時 2023-09-12 11:40:25
合計ジャッジ時間 14,519 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,404 KB
testcase_01 AC 76 ms
71,324 KB
testcase_02 AC 75 ms
71,316 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 77 ms
71,036 KB
testcase_06 AC 78 ms
71,324 KB
testcase_07 AC 77 ms
71,232 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 73 ms
71,036 KB
testcase_29 AC 73 ms
71,180 KB
testcase_30 AC 235 ms
90,804 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
D={};mod=998244353
D['U']=[];D['F']=[];D['W']=[];D['P']=[]
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

al=0;A=[]
for _ in range(N):
  x,y=input().split()
  y=int(y)
  al+=y
  D[x].append(y)

a,b,c=0,0,0
zz=modinv(N-1,mod)
for u in D['U']:
  x=pow(N-1,u,mod)
  y=pow(N-2,u,mod)
  z=pow(zz,u,mod)
  d=(x-y)*z%mod 
  a+=d 
  a%=mod
  
for u in D['F']:
  x=pow(N-1,u,mod)
  y=pow(N-2,u,mod)
  z=pow(zz,u,mod)
  d=(x-y)*z%mod 
  b+=d 
  b%=mod

for u in D['W']:
  x=pow(N-1,u,mod)
  y=pow(N-2,u,mod)
  z=pow(zz,u,mod)
  d=(x-y)*z%mod 
  c+=d 
  c%=mod
  
d=pow(N-1,al,mod)
ans=a
ans*=b
ans%=mod 
ans*=c
ans%=mod
ans*=d
ans%=mod
print(ans)
0