結果
問題 | No.1239 Multiplication -2 |
ユーザー | shotoyoo |
提出日時 | 2020-09-26 00:16:59 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 361 ms / 2,000 ms |
コード長 | 2,378 bytes |
コンパイル時間 | 301 ms |
コンパイル使用メモリ | 82,188 KB |
実行使用メモリ | 106,752 KB |
最終ジャッジ日時 | 2024-06-28 08:28:38 |
合計ジャッジ時間 | 7,274 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
53,632 KB |
testcase_01 | AC | 45 ms
54,016 KB |
testcase_02 | AC | 46 ms
53,760 KB |
testcase_03 | AC | 61 ms
64,768 KB |
testcase_04 | AC | 64 ms
66,304 KB |
testcase_05 | AC | 62 ms
64,768 KB |
testcase_06 | AC | 48 ms
54,272 KB |
testcase_07 | AC | 48 ms
54,912 KB |
testcase_08 | AC | 46 ms
53,760 KB |
testcase_09 | AC | 45 ms
53,760 KB |
testcase_10 | AC | 45 ms
53,504 KB |
testcase_11 | AC | 46 ms
54,016 KB |
testcase_12 | AC | 47 ms
54,016 KB |
testcase_13 | AC | 45 ms
54,016 KB |
testcase_14 | AC | 46 ms
53,760 KB |
testcase_15 | AC | 251 ms
84,480 KB |
testcase_16 | AC | 286 ms
91,688 KB |
testcase_17 | AC | 114 ms
106,112 KB |
testcase_18 | AC | 111 ms
105,788 KB |
testcase_19 | AC | 102 ms
103,932 KB |
testcase_20 | AC | 116 ms
106,752 KB |
testcase_21 | AC | 207 ms
104,384 KB |
testcase_22 | AC | 204 ms
104,312 KB |
testcase_23 | AC | 193 ms
96,672 KB |
testcase_24 | AC | 186 ms
96,116 KB |
testcase_25 | AC | 69 ms
87,552 KB |
testcase_26 | AC | 134 ms
94,208 KB |
testcase_27 | AC | 260 ms
83,892 KB |
testcase_28 | AC | 351 ms
101,120 KB |
testcase_29 | AC | 331 ms
101,156 KB |
testcase_30 | AC | 285 ms
87,128 KB |
testcase_31 | AC | 304 ms
94,328 KB |
testcase_32 | AC | 361 ms
104,456 KB |
testcase_33 | AC | 321 ms
96,768 KB |
testcase_34 | AC | 294 ms
94,464 KB |
testcase_35 | AC | 287 ms
84,480 KB |
testcase_36 | AC | 268 ms
83,560 KB |
ソースコード
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x+"\n") n = int(input()) a = list(map(int, input().split())) ls = [] from collections import deque l = deque() flg = False left = True first = True right = False seen0 = False for num in a: if num==0: if l: if flg: if first and seen0: left = False first = False ls.append(list(l)) l = deque() flg = False seen0 = True elif (num==2 or num==-2) and flg: ls.append(list(l)) if seen0 and first: left = False first = False while abs(l[0])!=2: l.popleft() l.popleft() l.append(num) flg = True elif (num==2 or num==-2): l.append(num) flg = True else: l.append(num) if l and flg: if seen0 and first: left = False ls.append(list(l)) right = True M = 998244353 inv2 = pow(2, M-2, M) invs = [None]*(n+10) invs[0] = 1 for i in range(1, n+10): invs[i] = invs[i-1]*inv2 invs[i] %= M def sub(l, left=False, right=False): if 2 in l: ind = l.index(2) flg2 = True else: ind = l.index(-2) flg2 = False e0 = inv2 if (ind>0 or not left) else 1 o0 = 0 e1 = inv2 if (ind<len(l)-1 or not right) else 1 o1 = 0 even = True for i in range(ind): if l[ind-i-1]==-1: even = not even tmp = invs[i+2] if (i<ind-1 or (not left)) else invs[i+1] if even: e0 += tmp else: o0 += tmp even = True for i in range(len(l)-ind-1): if l[ind+i+1]==-1: even = not even tmp = invs[i+2] if (i<len(l)-ind-2 or (not right)) else invs[i+1] if even: e1 += tmp else: o1 += tmp if not flg2: ans = e0*e1 + o0*o1 else: ans = e0*o1 + e1*o0 # print(left, right, e0, e1, o0, o1, ans%M) return ans%M if len(ls)==0: ans = 0 elif len(ls)==1: ans = sub(ls[0], left=left, right=right) else: ans = 0 ans += sub(ls[0], left=left) ans %= M for i in range(1, len(ls)-1): ans += sub(ls[i]) ans %= M ans += sub(ls[-1], right=right) ans %= M print(ans%M)