結果

問題 No.1239 Multiplication -2
ユーザー mkawa2mkawa2
提出日時 2021-08-08 18:42:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,189 ms / 2,000 ms
コード長 1,107 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 12,024 KB
実行使用メモリ 36,564 KB
最終ジャッジ日時 2023-10-19 19:08:58
合計ジャッジ時間 19,978 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,092 KB
testcase_01 AC 29 ms
10,092 KB
testcase_02 AC 30 ms
10,092 KB
testcase_03 AC 39 ms
10,168 KB
testcase_04 AC 39 ms
10,164 KB
testcase_05 AC 41 ms
10,172 KB
testcase_06 AC 33 ms
10,108 KB
testcase_07 AC 33 ms
10,104 KB
testcase_08 AC 31 ms
10,092 KB
testcase_09 AC 30 ms
10,092 KB
testcase_10 AC 30 ms
10,092 KB
testcase_11 AC 29 ms
10,092 KB
testcase_12 AC 30 ms
10,092 KB
testcase_13 AC 30 ms
10,092 KB
testcase_14 AC 30 ms
10,092 KB
testcase_15 AC 299 ms
12,632 KB
testcase_16 AC 486 ms
14,456 KB
testcase_17 AC 1,122 ms
13,276 KB
testcase_18 AC 1,129 ms
13,276 KB
testcase_19 AC 1,087 ms
15,064 KB
testcase_20 AC 1,152 ms
23,216 KB
testcase_21 AC 1,189 ms
36,564 KB
testcase_22 AC 901 ms
13,256 KB
testcase_23 AC 883 ms
29,676 KB
testcase_24 AC 679 ms
19,480 KB
testcase_25 AC 131 ms
12,188 KB
testcase_26 AC 810 ms
32,788 KB
testcase_27 AC 344 ms
16,456 KB
testcase_28 AC 1,065 ms
32,892 KB
testcase_29 AC 1,164 ms
34,176 KB
testcase_30 AC 439 ms
13,820 KB
testcase_31 AC 646 ms
15,568 KB
testcase_32 AC 1,057 ms
19,464 KB
testcase_33 AC 748 ms
16,292 KB
testcase_34 AC 698 ms
15,940 KB
testcase_35 AC 363 ms
12,916 KB
testcase_36 AC 325 ms
12,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
md = 998244353
# md = 10**9+7

from collections import defaultdict

n = II()
aa = LI()

dp = defaultdict(int)
c2 = 0
s = 1
dp[c2, s] = 1
two = 1

ans = 0
for i, a in enumerate(aa):
    if a==0:
        dp = defaultdict(int)
        c2 = 0
        s = 1
        dp[c2, s] = 1
        two = 2
    else:
        if abs(a) == 2: c2 += 1
        if a < 0: s *= -1
        dp[c2, s] += two
        if i < n-1: two = two*2%md
        ans += dp[c2-1, -s]*pow(two, md-2, md)%md
        ans %= md
        # print(ans, dp)

print(ans)
0