結果

問題 No.2168 双頭ヒドラゲーム
ユーザー testestesttestestest
提出日時 2022-12-08 12:07:23
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 71,600 KB
最終ジャッジ日時 2023-08-04 13:40:58
合計ジャッジ時間 3,205 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,164 KB
testcase_01 AC 71 ms
71,088 KB
testcase_02 AC 71 ms
71,560 KB
testcase_03 AC 68 ms
71,456 KB
testcase_04 AC 69 ms
71,340 KB
testcase_05 AC 72 ms
71,584 KB
testcase_06 AC 73 ms
71,564 KB
testcase_07 AC 71 ms
71,480 KB
testcase_08 AC 69 ms
71,364 KB
testcase_09 AC 66 ms
71,600 KB
testcase_10 AC 65 ms
71,432 KB
testcase_11 AC 68 ms
71,244 KB
testcase_12 AC 67 ms
71,276 KB
testcase_13 AC 66 ms
71,388 KB
testcase_14 AC 68 ms
71,384 KB
testcase_15 AC 66 ms
71,476 KB
testcase_16 AC 72 ms
71,212 KB
testcase_17 AC 69 ms
71,344 KB
testcase_18 AC 70 ms
71,460 KB
testcase_19 AC 71 ms
71,292 KB
testcase_20 AC 69 ms
71,436 KB
testcase_21 AC 70 ms
71,316 KB
testcase_22 AC 69 ms
71,352 KB
testcase_23 AC 68 ms
71,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 cmp(SR,T)
	if flag==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)
0