結果

問題 No.2031 Colored Brackets
ユーザー とりゐとりゐ
提出日時 2022-06-15 22:27:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 436 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 77,512 KB
最終ジャッジ日時 2023-10-13 20:57:09
合計ジャッジ時間 5,012 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,232 KB
testcase_01 AC 69 ms
71,328 KB
testcase_02 AC 72 ms
71,060 KB
testcase_03 AC 74 ms
75,468 KB
testcase_04 AC 98 ms
77,512 KB
testcase_05 AC 96 ms
77,188 KB
testcase_06 AC 93 ms
77,132 KB
testcase_07 AC 74 ms
75,380 KB
testcase_08 AC 106 ms
77,148 KB
testcase_09 AC 111 ms
76,964 KB
testcase_10 AC 117 ms
77,084 KB
testcase_11 AC 112 ms
77,268 KB
testcase_12 AC 119 ms
77,204 KB
testcase_13 AC 102 ms
76,944 KB
testcase_14 AC 118 ms
77,152 KB
testcase_15 AC 122 ms
77,200 KB
testcase_16 AC 120 ms
77,268 KB
testcase_17 AC 123 ms
77,420 KB
testcase_18 AC 114 ms
77,196 KB
testcase_19 AC 113 ms
77,408 KB
testcase_20 AC 109 ms
77,248 KB
testcase_21 AC 105 ms
77,376 KB
testcase_22 AC 110 ms
77,200 KB
testcase_23 AC 120 ms
77,392 KB
testcase_24 AC 71 ms
71,344 KB
testcase_25 AC 72 ms
71,360 KB
testcase_26 AC 70 ms
71,368 KB
testcase_27 AC 73 ms
75,388 KB
testcase_28 AC 70 ms
71,352 KB
testcase_29 AC 72 ms
71,384 KB
testcase_30 AC 71 ms
71,348 KB
testcase_31 AC 81 ms
76,220 KB
testcase_32 AC 70 ms
71,372 KB
testcase_33 AC 79 ms
76,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353
n=int(input())
S=input()
m=n//2+10

dp=[0]*m
dp[0]=1

now=0
for s in S:
  dpn=[0]*m
  if s=='(':
    for i in range(now+1):
      dpn[i]+=dp[i]
      if i!=m-1:
        dpn[i+1]+=dp[i]
    now+=1
  else:
    for i in range(now+1):
      dpn[i]+=dp[i]
      if i!=0:
        dpn[i-1]+=dp[i]
    now-=1
  if now<0 or now>n//2+5:
    print(0)
    exit()
  
  dp=[i%mod for i in dpn]
if now==0:
  print(dp[0])
else:
  print(0)
0