結果

問題 No.22 括弧の対応
コンテスト
ユーザー Mamonbo
提出日時 2015-10-07 19:16:53
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 95 ms / 5,000 ms
コード長 783 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 371 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 36,188 KB
最終ジャッジ日時 2026-04-02 21:44:53
合計ジャッジ時間 2,870 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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