結果

問題 No.1239 Multiplication -2
ユーザー chineristACchineristAC
提出日時 2020-10-01 16:22:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 288 ms / 2,000 ms
コード長 1,410 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,064 KB
実行使用メモリ 105,272 KB
最終ジャッジ日時 2023-09-21 06:55:48
合計ジャッジ時間 7,422 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,448 KB
testcase_01 AC 75 ms
71,244 KB
testcase_02 AC 74 ms
71,216 KB
testcase_03 AC 84 ms
76,124 KB
testcase_04 AC 85 ms
76,040 KB
testcase_05 AC 93 ms
76,828 KB
testcase_06 AC 77 ms
71,276 KB
testcase_07 AC 78 ms
71,204 KB
testcase_08 AC 74 ms
71,248 KB
testcase_09 AC 73 ms
71,328 KB
testcase_10 AC 74 ms
71,248 KB
testcase_11 AC 73 ms
71,348 KB
testcase_12 AC 73 ms
71,004 KB
testcase_13 AC 74 ms
71,032 KB
testcase_14 AC 74 ms
71,160 KB
testcase_15 AC 229 ms
84,572 KB
testcase_16 AC 249 ms
91,332 KB
testcase_17 AC 117 ms
104,656 KB
testcase_18 AC 123 ms
105,180 KB
testcase_19 AC 116 ms
104,860 KB
testcase_20 AC 138 ms
105,272 KB
testcase_21 AC 199 ms
105,148 KB
testcase_22 AC 189 ms
105,008 KB
testcase_23 AC 179 ms
96,544 KB
testcase_24 AC 217 ms
96,524 KB
testcase_25 AC 94 ms
91,016 KB
testcase_26 AC 204 ms
93,480 KB
testcase_27 AC 160 ms
82,824 KB
testcase_28 AC 235 ms
101,904 KB
testcase_29 AC 236 ms
102,064 KB
testcase_30 AC 182 ms
86,300 KB
testcase_31 AC 219 ms
93,444 KB
testcase_32 AC 264 ms
105,176 KB
testcase_33 AC 288 ms
96,308 KB
testcase_34 AC 241 ms
93,648 KB
testcase_35 AC 160 ms
84,240 KB
testcase_36 AC 195 ms
83,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
mod = 998244353
inv = pow(2,mod-2,mod)

res = 0

for i in range(N):
    if abs(A[i])==2:
        base = pow(2,max(i-1,0),mod)
        left_pos = base
        left_nega = 0
        prod = 1
        if i!=1:
            base = (base * inv) % mod
        for j in range(1,i+1):
            if abs(A[i-j])==1:
                prod *= A[i-j]
                if prod>0:
                    left_pos += base
                else:
                    left_nega += base
            else:
                break
            if j!=i-1:
                base = (base * inv) % mod

        base = pow(2,max(0,N-i-2),mod)
        right_pos = base
        right_nega = 0
        prod = 1
        if i!=N-2:
            base = (base * inv) % mod
        for j in range(1,N-i):
            if abs(A[i+j])==1:
                prod *= A[i+j]
                if prod>0:
                    right_pos += base
                else:
                    right_nega += base
            else:
                break
            if j!=N-i-2:
                base = (base * inv) % mod

        if A[i]==2:
            res += left_pos * right_nega + left_nega * right_pos
        else:
            res += left_pos * right_pos + left_nega * right_nega
        res %= mod
        #print(left_pos,left_nega,right_pos,right_nega)

#print(res)
ans = res * pow(2,(N-1)*(mod-2),mod)
print(ans%mod)
0