結果

問題 No.2398 ヒドラ崩し
ユーザー testestesttestestest
提出日時 2023-06-28 16:49:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 956 bytes
コンパイル時間 587 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 149,920 KB
最終ジャッジ日時 2023-09-18 20:32:07
合計ジャッジ時間 5,058 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,156 KB
testcase_01 AC 78 ms
71,408 KB
testcase_02 AC 74 ms
71,244 KB
testcase_03 AC 76 ms
71,492 KB
testcase_04 AC 75 ms
71,312 KB
testcase_05 AC 76 ms
71,356 KB
testcase_06 AC 76 ms
71,332 KB
testcase_07 AC 75 ms
71,340 KB
testcase_08 AC 75 ms
71,008 KB
testcase_09 AC 74 ms
71,356 KB
testcase_10 AC 76 ms
71,356 KB
testcase_11 AC 75 ms
71,012 KB
testcase_12 AC 75 ms
71,404 KB
testcase_13 AC 76 ms
71,320 KB
testcase_14 AC 75 ms
71,008 KB
testcase_15 AC 77 ms
71,240 KB
testcase_16 AC 76 ms
71,240 KB
testcase_17 AC 76 ms
71,284 KB
testcase_18 AC 76 ms
71,408 KB
testcase_19 AC 75 ms
71,360 KB
testcase_20 AC 78 ms
71,252 KB
testcase_21 AC 76 ms
71,056 KB
testcase_22 AC 75 ms
71,328 KB
testcase_23 AC 76 ms
71,460 KB
testcase_24 AC 95 ms
75,844 KB
testcase_25 AC 89 ms
76,220 KB
testcase_26 AC 182 ms
109,468 KB
testcase_27 AC 193 ms
122,116 KB
testcase_28 AC 235 ms
119,888 KB
testcase_29 AC 247 ms
149,920 KB
testcase_30 AC 169 ms
111,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def decompose_all(S,l=0):
  # (str,int)->hydra,int
  # 次に見るところを返す
  ret=[]
  while l<len(S) and S[l]=="(":
    h,l=decompose_all(S,l+1)
    ret.append(h)
  return ret,l+1

def get_righttop(arr):
  # hydra -> hydra
  logright=arr[-1]
  if logright==[]: return [[]]
  logrightlogright=logright[-1]
  if logrightlogright==[]: return arr[-1:]
  return get_righttop(logright)

def process(arr):
  # hydra -> hydra
  logright=arr.pop()
  if logright==[]: return arr
  logrightlogright=logright[-1]
  if logrightlogright==[]:
    logright.pop()
    arr.append(logright)
    return arr
  arr.append(process(logright))
  return arr

def g(arr):
  # hydra -> int
  if arr==[]: return 0
  righttop=get_righttop(arr)
  if righttop==[[]]: return 1 if g(process(arr))==0 else 0
  if righttop==[[[]]]: return 100
  return 1 if g(process(righttop))==0 else 0

import sys
sys.setrecursionlimit(10**9)

S=input()
print(0 if g(decompose_all(S)[0]) else 1)
0