結果
問題 | No.1239 Multiplication -2 |
ユーザー | shotoyoo |
提出日時 | 2020-09-26 00:02:40 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,439 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 82,496 KB |
実行使用メモリ | 106,624 KB |
最終ジャッジ日時 | 2024-06-28 08:25:48 |
合計ジャッジ時間 | 7,465 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
54,144 KB |
testcase_01 | AC | 47 ms
53,632 KB |
testcase_02 | AC | 44 ms
54,016 KB |
testcase_03 | AC | 57 ms
64,768 KB |
testcase_04 | AC | 59 ms
66,408 KB |
testcase_05 | AC | 58 ms
65,408 KB |
testcase_06 | AC | 45 ms
54,656 KB |
testcase_07 | AC | 46 ms
55,040 KB |
testcase_08 | WA | - |
testcase_09 | AC | 44 ms
54,528 KB |
testcase_10 | AC | 44 ms
54,016 KB |
testcase_11 | AC | 44 ms
54,144 KB |
testcase_12 | WA | - |
testcase_13 | AC | 44 ms
54,144 KB |
testcase_14 | AC | 43 ms
54,272 KB |
testcase_15 | WA | - |
testcase_16 | AC | 297 ms
91,904 KB |
testcase_17 | AC | 108 ms
105,976 KB |
testcase_18 | AC | 113 ms
105,856 KB |
testcase_19 | AC | 105 ms
104,504 KB |
testcase_20 | AC | 123 ms
106,624 KB |
testcase_21 | AC | 210 ms
104,216 KB |
testcase_22 | AC | 207 ms
104,148 KB |
testcase_23 | AC | 193 ms
96,768 KB |
testcase_24 | AC | 187 ms
96,452 KB |
testcase_25 | AC | 70 ms
87,552 KB |
testcase_26 | AC | 124 ms
94,336 KB |
testcase_27 | AC | 253 ms
84,164 KB |
testcase_28 | AC | 336 ms
100,992 KB |
testcase_29 | AC | 337 ms
101,092 KB |
testcase_30 | AC | 285 ms
87,424 KB |
testcase_31 | AC | 305 ms
94,376 KB |
testcase_32 | AC | 361 ms
104,576 KB |
testcase_33 | AC | 322 ms
96,640 KB |
testcase_34 | AC | 297 ms
94,464 KB |
testcase_35 | AC | 272 ms
84,864 KB |
testcase_36 | WA | - |
ソースコード
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: seen0 = True if l: if flg: if first: left = False first = False ls.append(list(l)) l = deque() flg = False 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: if seen0 and first: left = False first = False 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)