結果

問題 No.1239 Multiplication -2
ユーザー marroncastlemarroncastle
提出日時 2020-09-26 01:46:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,060 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 86,448 KB
実行使用メモリ 105,032 KB
最終ジャッジ日時 2023-09-10 18:47:43
合計ジャッジ時間 8,336 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,028 KB
testcase_01 AC 74 ms
71,024 KB
testcase_02 AC 75 ms
70,844 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 75 ms
70,652 KB
testcase_12 AC 75 ms
70,744 KB
testcase_13 AC 75 ms
70,676 KB
testcase_14 AC 81 ms
70,716 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 299 ms
104,324 KB
testcase_22 AC 238 ms
104,624 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 96 ms
90,028 KB
testcase_26 AC 202 ms
93,140 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(1,N-1):
  if abs(A[i])==2:
    l_p = pow(2,i-1,mod)
    l_m = 0
    cuml = 1
    for j in range(i-1,0,-1):
      if abs(A[j])!=1:
        break
      cuml *= A[j]
      if cuml == 1:
        l_p += pow(2,j-1,mod)
      else:
        l_m += pow(2,j-1,mod)
    r_p = pow(2,N-2-i,mod)
    r_m = 0
    cumr = 1
    for j in range(i+1,N-1):
      if abs(A[j])!=1:
        break
      cumr *= A[j]
      if cumr == 1:
        r_p += pow(2,N-2-i,mod)
      else:
        r_m += pow(2,N-2-i,mod)
    if A[i]==2:
      ans += l_p * r_m + l_m * r_p
    else:
      ans += l_p * r_p + l_m * r_m
    ans %= mod
cum = 1
for i in range(N):
  cum *= A[i]
  if cum == -2:
    if i<N-1:
      ans += pow(2,N-2-i,mod)
    else:
      ans += pow(2,N-1-i,mod)
  if abs(cum)>2 or cum==0:
    break
cum = 1
for i in range(N-1,0,-1):
  cum *= A[i]
  if cum == -2:
    ans += pow(2,i-1,mod)
  if abs(cum)>2 or cum==0:
    break
ans %= mod
ans *= pow(pow(2,N-1,mod),mod-2,mod)
print(ans%mod)

0