結果

問題 No.22 括弧の対応
ユーザー Mamonbo
提出日時 2015-10-07 19:16:53
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 783 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-07-20 07:04:10
合計ジャッジ時間 1,425 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#coding=UTF-8

#Brain Fuc○の角括弧の対応についての私の解決策を書いてみようかしら
mojir=input()
hyo=mojir.split(' ')
N=int(hyo[0])
K=int(hyo[1])

S=input()
if S[K-1]=='(':
    depth=1
    for idx in range(K,N,1):
        if S[idx]=='(':
            depth=depth+1
        elif S[idx]==')':
            depth=depth-1
            if depth==0:
                #お巡りさん、こいつです
                print(idx+1)#0-orginに注意
                break
else:
    depth=1
    for idx in range(K-2,-1,-1):
        if S[idx]==')':
            depth=depth+1
        elif S[idx]=='(':
            depth=depth-1
            if depth==0:
                #お巡りさん、こいつです
                print(idx+1)#0-orginに注意
                break
0