結果
| 問題 | No.3503 Brackets Stack Query 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-17 21:12:15 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,126 bytes |
| 記録 | |
| コンパイル時間 | 492 ms |
| コンパイル使用メモリ | 85,376 KB |
| 実行使用メモリ | 156,928 KB |
| 最終ジャッジ日時 | 2026-04-17 21:13:15 |
| 合計ジャッジ時間 | 56,954 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 23 TLE * 7 |
ソースコード
#--------------------------------------------------
import sys
import functools
#sys.setrecursionlimit(10**9)
#codon↓--------------------------------------------
_factorial=[1]
def factorial(n):
while len(_factorial)<=n:
_factorial.append((_factorial[-1]*len(_factorial))%mod)
return _factorial[n]
def binom(n,r):
if r>=mod:
raise ValueError("r is too big")
if n<0:
return 0
if r>n:
return 0
if r<0:
return 0
ans=((factorial(n)*pow(factorial(r),mod-2,mod))%mod*pow(factorial(n-r),mod-2,mod))%mod
return ans
import string
import itertools
alp_low=list(string.ascii_lowercase)
alp_up=list(string.ascii_uppercase)
dij=[[0,1],[1,0],[0,-1],[-1,0]]
mod=998244353
INF=10**18
def dijkstra(edges, num_node,start):
"""
[node_num,weight>0][
(example)
Edges = [
[[1, 4], [2, 3]],
[[0, 1], [3, 1]],
[[3, 2]],
[],
]
"""
import heapq;n=[INF]*num_node;n[start]=0;n_name=[];heapq.heappush(n_name,[0,start])
while len(n_name):
_,min_p=heapq.heappop(n_name)
for f in edges[min_p]:
g,c=f
if n[min_p]+c<n[g]:n[g]=n[min_p]+c;heapq.heappush(n_name,[n[min_p]+c,g])
return n
def nin():
return list(map(int,input().split()))
def deq(x):
return [i-1 for i in x]
def pop_cnt(n):
ans=0
while n:
if n%2:
ans+=1
n//=2
return ans
def main():
q,=nin()
conv={"(":0, "|":1, ")":2}
now=[]
d={}
now_l=0
for i in range(q):
qq=input().split()
if qq[0]=="1":
now.append((conv[qq[1]],now_l))
now_l+=1
else:
if len(now)>0 and now[-1][1]==now_l-1:
now.pop(-1)
else:
now+=d[now_l-1]
now_l-=1
while len(now)>=3 and [now[-3][0],now[-2][0],now[-1][0]]==[0,1,2]:
d[now[-1][1]]=now[-3:-1]
for __ in range(3):
now.pop(-1)
if len(now)==0:
print("Yes")
else:
print("No")
if __name__=="__main__":
main()