結果

問題 No.1239 Multiplication -2
ユーザー eSeFeSeF
提出日時 2020-09-01 12:05:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,172 bytes
コンパイル時間 86 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 27,216 KB
最終ジャッジ日時 2024-04-29 09:12:54
合計ジャッジ時間 13,817 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,880 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 31 ms
11,008 KB
testcase_03 AC 51 ms
10,880 KB
testcase_04 AC 50 ms
10,752 KB
testcase_05 AC 53 ms
10,752 KB
testcase_06 AC 37 ms
10,880 KB
testcase_07 AC 37 ms
10,752 KB
testcase_08 AC 30 ms
10,880 KB
testcase_09 AC 30 ms
10,880 KB
testcase_10 AC 30 ms
10,880 KB
testcase_11 AC 30 ms
10,880 KB
testcase_12 AC 30 ms
10,880 KB
testcase_13 AC 30 ms
11,008 KB
testcase_14 AC 31 ms
10,880 KB
testcase_15 AC 752 ms
12,928 KB
testcase_16 AC 1,243 ms
14,704 KB
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 AC 1,648 ms
19,848 KB
testcase_24 AC 1,592 ms
18,224 KB
testcase_25 AC 1,253 ms
12,888 KB
testcase_26 AC 1,416 ms
18,740 KB
testcase_27 AC 644 ms
12,928 KB
testcase_28 TLE -
testcase_29 TLE -
testcase_30 AC 934 ms
13,952 KB
testcase_31 AC 1,394 ms
15,252 KB
testcase_32 TLE -
testcase_33 AC 1,629 ms
16,220 KB
testcase_34 AC 1,519 ms
15,816 KB
testcase_35 AC 777 ms
13,184 KB
testcase_36 AC 688 ms
12,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
MOD=998244353
def main():
    N=int(input())
    A=list(map(int,input().split()))
    dp=[[[0 for _ in range(3)] for _ in range(3)] for _ in range(2)]
    dp2=[[[0 for _ in range(3)] for _ in range(3)] for _ in range(2)]
    dp[0][0][0]=1
    for i in range(N):
        neg=(1 if A[i]<0 else 0)
        two=(2 if A[i]==0 else (1 if abs(A[i])==2 else 0))
        
        for j in range(2):
            for k in range(3):
                if i==0:
                    dp2[j][k][0]+=dp[j][k][0]
                else:
                    dp2[j][k][0]+=2*dp[j][k][0]
                dp2[(j+neg)%2][min(2,k+two)][1]+=dp[j][k][1]+dp[j][k][0]
                dp2[(j+neg)%2][min(2,k+two)][2]+=dp[j][k][1]+dp[j][k][0]
                if i==N-1:
                    dp2[j][k][2]+=dp[j][k][2]
                else:
                    dp2[j][k][2]+=2*dp[j][k][2]
        for j in range(2):
            for k in range(3):
                for l in range(3):
                    dp[j][k][l]=dp2[j][k][l]%MOD
                    dp2[j][k][l]=0
    ans=dp[1][1][2]
    print((ans*pow(pow(2,N-1,MOD),MOD-2,MOD))%MOD)
if __name__=='__main__':
    main()
0