結果

問題 No.2168 双頭ヒドラゲーム
ユーザー testestesttestestest
提出日時 2022-12-08 12:29:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,115 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 54,364 KB
最終ジャッジ日時 2024-04-22 11:28:55
合計ジャッジ時間 1,936 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
51,584 KB
testcase_01 AC 40 ms
52,224 KB
testcase_02 AC 38 ms
51,712 KB
testcase_03 AC 42 ms
51,840 KB
testcase_04 AC 38 ms
52,224 KB
testcase_05 AC 38 ms
51,968 KB
testcase_06 AC 39 ms
51,968 KB
testcase_07 AC 39 ms
51,712 KB
testcase_08 AC 38 ms
52,224 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 39 ms
51,712 KB
testcase_12 WA -
testcase_13 AC 40 ms
52,224 KB
testcase_14 AC 39 ms
51,840 KB
testcase_15 AC 39 ms
52,352 KB
testcase_16 WA -
testcase_17 AC 40 ms
52,096 KB
testcase_18 AC 39 ms
52,480 KB
testcase_19 AC 39 ms
52,352 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 39 ms
52,224 KB
testcase_23 AC 39 ms
52,352 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 -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)
0