結果

問題 No.1239 Multiplication -2
ユーザー eSeFeSeF
提出日時 2020-09-12 00:43:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 21,280 KB
最終ジャッジ日時 2023-08-28 10:25:37
合計ジャッジ時間 6,128 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
8,156 KB
testcase_01 AC 15 ms
8,084 KB
testcase_02 AC 14 ms
8,148 KB
testcase_03 AC 17 ms
8,336 KB
testcase_04 AC 17 ms
8,436 KB
testcase_05 AC 17 ms
8,260 KB
testcase_06 AC 16 ms
8,184 KB
testcase_07 AC 16 ms
8,184 KB
testcase_08 AC 15 ms
8,164 KB
testcase_09 AC 15 ms
8,248 KB
testcase_10 AC 17 ms
8,272 KB
testcase_11 AC 14 ms
8,312 KB
testcase_12 AC 15 ms
8,160 KB
testcase_13 AC 15 ms
8,248 KB
testcase_14 AC 15 ms
8,360 KB
testcase_15 AC 86 ms
11,044 KB
testcase_16 AC 133 ms
13,104 KB
testcase_17 AC 171 ms
17,760 KB
testcase_18 AC 211 ms
17,760 KB
testcase_19 AC 151 ms
17,436 KB
testcase_20 AC 189 ms
21,280 KB
testcase_21 AC 310 ms
17,340 KB
testcase_22 AC 240 ms
16,856 KB
testcase_23 AC 245 ms
19,436 KB
testcase_24 AC 187 ms
17,460 KB
testcase_25 AC 59 ms
13,340 KB
testcase_26 AC 253 ms
18,184 KB
testcase_27 AC 100 ms
10,812 KB
testcase_28 AC 300 ms
16,660 KB
testcase_29 AC 330 ms
17,636 KB
testcase_30 AC 127 ms
11,876 KB
testcase_31 AC 185 ms
13,636 KB
testcase_32 AC 302 ms
17,612 KB
testcase_33 AC 213 ms
14,596 KB
testcase_34 AC 200 ms
14,024 KB
testcase_35 AC 105 ms
11,128 KB
testcase_36 AC 95 ms
10,972 KB
権限があれば一括ダウンロードができます

ソースコード

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
            prod=0
            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