結果
| 問題 |
No.2168 双頭ヒドラゲーム
|
| コンテスト | |
| ユーザー |
👑 testestest
|
| 提出日時 | 2022-12-08 12:29:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,115 bytes |
| コンパイル時間 | 170 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 52,736 KB |
| 最終ジャッジ日時 | 2024-10-14 10:48:04 |
| 合計ジャッジ時間 | 1,922 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 WA * 6 |
ソースコード
def decompose_to_single(S):
#(A|B)(C|D)->[(A|B),(C|D)]
ret=[]
pre=0
depth=0
for i,c in enumerate(S):
if c=="(": depth+=1
if c==")": depth-=1
if depth==0:
ret.append(S[pre:i+1])
pre=i+1
return ret
def split(S):
#(A|B)->[A,B]
depth=0
for i,c in enumerate(S):
if c=="(": depth+=1
if c==")": depth-=1
if depth==1 and c=="|":
return (S[1:i],S[i+1:-1])
pre=i
def cmp_single(S,T,cmp):
#return S<=>T
if S=="":
if T=="": return 0
return -1
if T=="": return 1
SL,SR=split(S)
TL,TR=split(T)
flag=cmp(SL,TL)
if flag==-1:
return -1
#return cmp(SR,T)
if flag==1:
return 1
#return cmp(S,TR)
return cmp(SR,TR)
def normalize(S_list):
ret=[]
for s in S_list:
while ret and cmp_single(ret[-1],s,cmp)==-1: ret.pop()
ret.append(s)
return ret
def cmp(S,T):
#return S<=>T
S_list=normalize(decompose_to_single(S))
T_list=normalize(decompose_to_single(T))
for s,t in zip(S_list,T_list):
ret=cmp_single(s,t,cmp)
if ret: return ret
if len(S_list)<len(T_list): return -1
if len(S_list)>len(T_list): return 1
return 0
S=input()
T=input()
print(0 if cmp(S,T)>0 else 1)
testestest