結果

問題 No.1239 Multiplication -2
ユーザー titiatitia
提出日時 2020-09-25 23:13:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,830 ms / 2,000 ms
コード長 1,823 bytes
コンパイル時間 1,262 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 21,468 KB
最終ジャッジ日時 2023-09-10 16:14:51
合計ジャッジ時間 24,732 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,124 KB
testcase_01 AC 16 ms
7,956 KB
testcase_02 AC 17 ms
8,124 KB
testcase_03 AC 29 ms
8,116 KB
testcase_04 AC 30 ms
7,952 KB
testcase_05 AC 32 ms
8,084 KB
testcase_06 AC 21 ms
8,096 KB
testcase_07 AC 21 ms
8,068 KB
testcase_08 AC 16 ms
8,044 KB
testcase_09 AC 17 ms
8,048 KB
testcase_10 AC 16 ms
8,016 KB
testcase_11 AC 16 ms
8,084 KB
testcase_12 AC 16 ms
8,024 KB
testcase_13 AC 17 ms
8,120 KB
testcase_14 AC 16 ms
8,120 KB
testcase_15 AC 335 ms
10,912 KB
testcase_16 AC 553 ms
12,608 KB
testcase_17 AC 1,238 ms
11,456 KB
testcase_18 AC 1,780 ms
11,536 KB
testcase_19 AC 875 ms
13,300 KB
testcase_20 AC 1,259 ms
21,468 KB
testcase_21 AC 1,830 ms
11,452 KB
testcase_22 AC 1,196 ms
11,436 KB
testcase_23 AC 1,335 ms
19,532 KB
testcase_24 AC 881 ms
17,608 KB
testcase_25 AC 56 ms
10,432 KB
testcase_26 AC 1,237 ms
18,308 KB
testcase_27 AC 513 ms
10,800 KB
testcase_28 AC 1,631 ms
16,348 KB
testcase_29 AC 1,774 ms
17,660 KB
testcase_30 AC 618 ms
12,064 KB
testcase_31 AC 927 ms
13,832 KB
testcase_32 AC 1,542 ms
17,652 KB
testcase_33 AC 1,072 ms
14,724 KB
testcase_34 AC 1,000 ms
14,044 KB
testcase_35 AC 495 ms
11,232 KB
testcase_36 AC 443 ms
10,872 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