結果

問題 No.22 括弧の対応
ユーザー shimashima_k
提出日時 2015-04-25 13:55:35
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 740 bytes
コンパイル時間 412 ms
コンパイル使用メモリ 56,364 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 06:59:48
合計ジャッジ時間 1,376 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
using namespace std;

int main(){
    int n,k;
    string str;
    cin >> n>>k;
    cin >> str;

    if (str[k-1] == '(') {
        int deep = 1;
        for (int i=k; i < str.size(); i++){
            if (str[i] == '(') {
                deep++;
            } else {
                deep--;
            }
            if (deep <= 0){
                cout<<i+1<<endl;
                break;
            }
        }
    } else {
        int deep = 1;
        for (int i=k-2; i >=0; i--){
            if (str[i] ==  ')') {
                deep++;
            } else {
                deep--;
            }
            if (deep <= 0){
                cout<<i+1<<endl;
                break;
            }
        }

    }

}
0