結果

問題 No.1239 Multiplication -2
ユーザー marroncastlemarroncastle
提出日時 2020-09-26 01:53:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 328 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 86,508 KB
実行使用メモリ 104,804 KB
最終ジャッジ日時 2023-09-10 19:01:20
合計ジャッジ時間 8,326 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
70,992 KB
testcase_01 AC 69 ms
70,792 KB
testcase_02 AC 70 ms
70,928 KB
testcase_03 AC 147 ms
75,996 KB
testcase_04 AC 82 ms
76,016 KB
testcase_05 AC 82 ms
76,236 KB
testcase_06 AC 72 ms
70,572 KB
testcase_07 AC 72 ms
70,948 KB
testcase_08 AC 69 ms
71,048 KB
testcase_09 AC 70 ms
70,752 KB
testcase_10 AC 70 ms
70,676 KB
testcase_11 AC 69 ms
70,944 KB
testcase_12 AC 70 ms
71,052 KB
testcase_13 AC 69 ms
70,920 KB
testcase_14 AC 69 ms
71,048 KB
testcase_15 AC 216 ms
83,600 KB
testcase_16 AC 252 ms
90,668 KB
testcase_17 AC 277 ms
104,384 KB
testcase_18 AC 289 ms
104,276 KB
testcase_19 AC 164 ms
103,848 KB
testcase_20 AC 256 ms
104,688 KB
testcase_21 AC 293 ms
103,996 KB
testcase_22 AC 230 ms
104,704 KB
testcase_23 AC 237 ms
95,272 KB
testcase_24 AC 236 ms
96,020 KB
testcase_25 AC 89 ms
89,924 KB
testcase_26 AC 197 ms
93,104 KB
testcase_27 AC 170 ms
82,416 KB
testcase_28 AC 293 ms
100,892 KB
testcase_29 AC 322 ms
101,268 KB
testcase_30 AC 196 ms
86,008 KB
testcase_31 AC 218 ms
93,056 KB
testcase_32 AC 318 ms
104,804 KB
testcase_33 AC 328 ms
95,772 KB
testcase_34 AC 280 ms
93,236 KB
testcase_35 AC 200 ms
83,660 KB
testcase_36 AC 205 ms
82,496 KB
権限があれば一括ダウンロードができます

ソースコード

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-j,mod)
      else:
        r_m += pow(2,N-2-j,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