結果

問題 No.1239 Multiplication -2
ユーザー marroncastlemarroncastle
提出日時 2020-09-26 01:43:59
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,006 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 83,340 KB
最終ジャッジ日時 2023-09-10 18:45:23
合計ジャッジ時間 8,604 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
75,700 KB
testcase_01 AC 71 ms
71,240 KB
testcase_02 AC 71 ms
71,272 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 71 ms
71,156 KB
testcase_12 AC 71 ms
71,408 KB
testcase_13 AC 72 ms
71,024 KB
testcase_14 AC 71 ms
71,372 KB
testcase_15 TLE -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 1<<(i-1)
    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 += 1<<(j-1)
      else:
        l_m += 1<<(j-1)
    r_p = 1<<(N-2-i)
    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 += 1<<(N-2-i)
      else:
        r_m += 1<<(N-2-i)
    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 += 1<<(N-2-i)
    else:
      ans += 1<<(N-1-i)
  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 += 1<<(i-1)
  if abs(cum)>2 or cum==0:
    break
ans %= mod
ans *= pow(pow(2,N-1,mod),mod-2,mod)
print(ans%mod)

0