結果

問題 No.1239 Multiplication -2
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-09-25 22:36:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 1,660 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 87,068 KB
実行使用メモリ 105,260 KB
最終ジャッジ日時 2023-09-10 15:54:12
合計ジャッジ時間 8,630 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,372 KB
testcase_01 AC 75 ms
71,476 KB
testcase_02 AC 78 ms
71,324 KB
testcase_03 AC 85 ms
76,576 KB
testcase_04 AC 85 ms
76,348 KB
testcase_05 AC 88 ms
76,804 KB
testcase_06 AC 77 ms
71,160 KB
testcase_07 AC 78 ms
71,392 KB
testcase_08 AC 74 ms
71,128 KB
testcase_09 AC 74 ms
71,392 KB
testcase_10 AC 74 ms
71,368 KB
testcase_11 AC 75 ms
71,604 KB
testcase_12 AC 75 ms
71,316 KB
testcase_13 AC 75 ms
71,400 KB
testcase_14 AC 74 ms
71,320 KB
testcase_15 AC 271 ms
83,988 KB
testcase_16 AC 336 ms
91,292 KB
testcase_17 AC 208 ms
104,372 KB
testcase_18 AC 264 ms
104,644 KB
testcase_19 AC 175 ms
104,680 KB
testcase_20 AC 228 ms
105,104 KB
testcase_21 AC 314 ms
104,504 KB
testcase_22 AC 257 ms
104,532 KB
testcase_23 AC 262 ms
95,824 KB
testcase_24 AC 261 ms
95,820 KB
testcase_25 AC 93 ms
90,612 KB
testcase_26 AC 218 ms
93,532 KB
testcase_27 AC 195 ms
83,304 KB
testcase_28 AC 332 ms
101,764 KB
testcase_29 AC 344 ms
101,540 KB
testcase_30 AC 217 ms
86,716 KB
testcase_31 AC 249 ms
93,272 KB
testcase_32 AC 383 ms
105,260 KB
testcase_33 AC 327 ms
95,680 KB
testcase_34 AC 273 ms
93,532 KB
testcase_35 AC 193 ms
84,364 KB
testcase_36 AC 223 ms
83,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

-2になる各区間に関して
いくつ出現するかを求めればいい?
各2 or -2から左右を見ていく

0か|2|にぶつかったら終わり
各場所最大2回しか見ないのでおk

全ての区間の個数も数え上げる
左端がいくつあるか答えればいい
ある場所を左端にするとき、残りの切り方を数えればいいのでおわり

A,B個左右に残ってる場合の通り数は
2^(A-1) * 2^(B-1)

"""

from sys import stdin
import sys

def inverse(a,mod): #aのmodを法にした逆元を返す
    return pow(a,mod-2,mod)

def ppow(x,y,mod):
    if y >= 0:
        return pow(x,y,mod)
    else:
        return 1

N = int(stdin.readline())
a = list(map(int,stdin.readline().split()))

if N == 1:
    if a[0] == -2:
        print (1)
    else:
        print (0)
    sys.exit()


mod = 998244353
ALL = ( pow(2,N-1,mod) + (N-1) * pow(2,N-2,mod) ) % mod
half = inverse(2,mod)

ans = 0
for i in range(N):

    if abs(a[i]) != 2:
        continue

    dic = {}
    dic[2] = 0
    dic[-2] = 0
    dic[a[i]] = ppow(2,N-1-i-1,mod)

    now = a[i]
    for j in range(i+1,N):
        if abs(a[j]) != 1:
            break
        now *= a[j]
        dic[now] += ppow(2,N-j-1-1,mod)

    ans += dic[-2] * ppow(2,i-1,mod)

    now = 1
    for j in range(i-1,-1,-1):
        if abs(a[j]) != 1:
            break
        now *= a[j]
        if now == 1:
            ans += dic[-2] * ppow(2,j-1,mod)
        else:
            ans += dic[2] * ppow(2,j-1,mod)

    ans %= mod

    #print (ans,dic)

#print (ans , ALL , file=sys.stderr)
print (ans * inverse(pow(2,N-1,mod),mod) % mod)
        
        
        
0