結果

問題 No.1239 Multiplication -2
ユーザー titiatitia
提出日時 2020-09-25 23:13:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 562 ms / 2,000 ms
コード長 1,823 bytes
コンパイル時間 2,595 ms
コンパイル使用メモリ 86,452 KB
実行使用メモリ 104,868 KB
最終ジャッジ日時 2023-09-10 16:14:08
合計ジャッジ時間 10,932 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,376 KB
testcase_01 AC 76 ms
71,260 KB
testcase_02 AC 74 ms
71,172 KB
testcase_03 AC 86 ms
75,996 KB
testcase_04 AC 85 ms
76,132 KB
testcase_05 AC 107 ms
77,696 KB
testcase_06 AC 78 ms
71,072 KB
testcase_07 AC 78 ms
71,340 KB
testcase_08 AC 76 ms
71,288 KB
testcase_09 AC 75 ms
71,072 KB
testcase_10 AC 76 ms
71,072 KB
testcase_11 AC 76 ms
71,320 KB
testcase_12 AC 75 ms
71,076 KB
testcase_13 AC 74 ms
71,288 KB
testcase_14 AC 74 ms
71,256 KB
testcase_15 AC 268 ms
84,260 KB
testcase_16 AC 248 ms
91,144 KB
testcase_17 AC 375 ms
104,468 KB
testcase_18 AC 517 ms
104,488 KB
testcase_19 AC 291 ms
104,104 KB
testcase_20 AC 388 ms
104,800 KB
testcase_21 AC 508 ms
104,696 KB
testcase_22 AC 379 ms
104,236 KB
testcase_23 AC 439 ms
95,952 KB
testcase_24 AC 304 ms
95,636 KB
testcase_25 AC 97 ms
90,456 KB
testcase_26 AC 330 ms
93,084 KB
testcase_27 AC 233 ms
83,188 KB
testcase_28 AC 495 ms
101,104 KB
testcase_29 AC 562 ms
101,564 KB
testcase_30 AC 255 ms
86,580 KB
testcase_31 AC 356 ms
93,376 KB
testcase_32 AC 558 ms
104,868 KB
testcase_33 AC 382 ms
95,656 KB
testcase_34 AC 377 ms
93,440 KB
testcase_35 AC 233 ms
84,164 KB
testcase_36 AC 223 ms
83,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

mod=998244353

PLUS=[]
MINUS=[]
ANS=0

for i in range(N):
    if A[i]==2 or A[i]==-2:
        if i==0:
            LEFTP=1
            LEFTM=0
        else:
            LEFTP=pow(2,mod-2,mod)
            LEFTM=0

        LEFT=1

        for j in range(i-1,-1,-1):
            LEFT*=A[j]

            if j!=0:
                if LEFT==1:
                    LEFTP+=pow(pow(2,mod-2,mod),i-j+1,mod)
                elif LEFT==-1:
                    LEFTM+=pow(pow(2,mod-2,mod),i-j+1,mod)
                else:
                    break
            else:
                if LEFT==1:
                    LEFTP+=pow(pow(2,mod-2,mod),i-j,mod)
                elif LEFT==-1:
                    LEFTM+=pow(pow(2,mod-2,mod),i-j,mod)
                else:
                    break
                

        if i==N-1:
            RIGHTP=1
            RIGHTM=0
        else:
            RIGHTP=pow(2,mod-2,mod)
            RIGHTM=0

        RIGHT=1

        for j in range(i+1,N):
            RIGHT*=A[j]

            if j!=N-1:
                if RIGHT==1:
                    RIGHTP+=pow(pow(2,mod-2,mod),j-i+1,mod)
                elif RIGHT==-1:
                    RIGHTM+=pow(pow(2,mod-2,mod),j-i+1,mod)
                else:
                    break
            else:
                if RIGHT==1:
                    RIGHTP+=pow(pow(2,mod-2,mod),j-i,mod)
                elif RIGHT==-1:
                    RIGHTM+=pow(pow(2,mod-2,mod),j-i,mod)
                else:
                    break

        if A[i]==2:
            ANS+=LEFTP*RIGHTM+LEFTM*RIGHTP
        else:
            ANS+=LEFTP*RIGHTP+LEFTM*RIGHTM

        ANS%=mod

print(ANS)
            
            

        
                
            
            
            
0