結果

問題 No.1239 Multiplication -2
ユーザー eSeFeSeF
提出日時 2020-09-12 00:38:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,080 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 21,424 KB
最終ジャッジ日時 2023-08-28 10:16:52
合計ジャッジ時間 6,017 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,300 KB
testcase_01 AC 16 ms
8,192 KB
testcase_02 AC 15 ms
8,332 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 15 ms
8,128 KB
testcase_10 AC 16 ms
8,292 KB
testcase_11 AC 15 ms
8,200 KB
testcase_12 AC 15 ms
8,296 KB
testcase_13 AC 15 ms
8,196 KB
testcase_14 AC 15 ms
8,208 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 172 ms
17,844 KB
testcase_18 AC 211 ms
17,728 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 311 ms
17,060 KB
testcase_22 AC 240 ms
16,888 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 61 ms
13,488 KB
testcase_26 AC 257 ms
18,240 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
MOD=998244353
def main():
    N=int(input())
    a=list(map(int,input().split()))
    pw2=[1]*(N+1)
    for i in range(N):
        pw2[i+1]=(pw2[i]*2)%MOD
    ans=0
    for i in range(N):
        if abs(a[i])==2:
            prod=0
            cl=[pw2[max(0,i-1)],0]
            for j in range(i-1,-1,-1):
                if abs(a[j])==1:
                    if a[j]==-1:
                        prod^=1
                    cl[prod]=(cl[prod]+pw2[max(0,j-1)])%MOD
                else:
                    break
            cr=[pw2[max(0,N-2-i)],0]
            for j in range(i+1,N):
                if abs(a[j])==1:
                    if a[j]==-1:
                        prod^=1
                    cr[prod]=(cr[prod]+pw2[max(0,N-2-j)])%MOD
                else:
                    break
            if a[i]==2:
                ans=(ans+cl[0]*cr[1]+cl[1]*cr[0])%MOD
            else:
                ans=(ans+cl[0]*cr[0]+cl[1]*cr[1])%MOD
    ans*=pow(pow(2,N-1,MOD),MOD-2,MOD)
    ans%=MOD
    print(ans)
if __name__=='__main__':
    main()
0