結果
| 問題 | No.22 括弧の対応 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-06-24 12:33:47 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 98 ms / 5,000 ms |
| コード長 | 427 bytes |
| 記録 | |
| コンパイル時間 | 518 ms |
| コンパイル使用メモリ | 20,700 KB |
| 実行使用メモリ | 15,356 KB |
| 最終ジャッジ日時 | 2026-05-08 11:52:22 |
| 合計ジャッジ時間 | 3,329 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
n,k=map(int,input().split())
k-=1
s=input()
stack=[]
ans=[]
for i in range(n):
if stack:
last,ind=stack[-1][0],stack[-1][1]
if last=='(' and s[i]==')':
stack.pop()
ans.append((ind,i))
else:
stack.append((s[i],i))
else:
stack.append((s[i],i))
for x,y in ans:
if x==k:
print(y+1)
break
elif y==k:
print(x+1)
break