結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,288 KB
testcase_01 AC 39 ms
52,808 KB
testcase_02 AC 39 ms
52,824 KB
testcase_03 AC 39 ms
53,008 KB
testcase_04 AC 39 ms
53,156 KB
testcase_05 AC 41 ms
53,268 KB
testcase_06 AC 40 ms
53,280 KB
testcase_07 AC 39 ms
52,616 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 39 ms
53,268 KB
testcase_19 AC 39 ms
53,572 KB
testcase_20 AC 39 ms
54,104 KB
testcase_21 AC 40 ms
52,624 KB
testcase_22 AC 40 ms
52,668 KB
testcase_23 AC 39 ms
53,612 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