結果
問題 |
No.22 括弧の対応
|
ユーザー |
|
提出日時 | 2022-06-24 12:33:47 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 42 ms / 5,000 ms |
コード長 | 427 bytes |
コンパイル時間 | 441 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 11,392 KB |
最終ジャッジ日時 | 2024-11-08 05:32:39 |
合計ジャッジ時間 | 1,868 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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