結果

問題 No.1092 modular arithmetic
ユーザー vwxyz
提出日時 2024-07-17 09:57:28
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 257 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,720 KB
最終ジャッジ日時 2024-07-17 09:57:38
合計ジャッジ時間 7,354 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

P,N=map(int,input().split())
A=list(map(int,input().split()))
S=input()
ans=A[0]
for a,s in zip(A[1:],S):
    if s=="+":
        ans+=a
    elif s=="-":
        ans-=a
    elif s=="*":
        ans*=a
    else:
        ans*=pow(a,P-2,P)
    ans%=P
print(ans)
0