結果

問題 No.22 括弧の対応
ユーザー Elk
提出日時 2018-07-02 00:21:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 682 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 168,916 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:32:30
合計ジャッジ時間 2,334 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int N, K, i, cnt = 1, tmp;
    string str;
    vector <int> num;

    cin >> N >> K >> str;
    for(i = 0; i < N; i++){
        if(str[i] == '('){
            num.push_back(cnt);
        }else{
            tmp = *(num.end() - 1);
            num.erase(num.end() - 1);
            if(str[K - 1] == '('){
                if(tmp == K){
                    cout << i + 1 << endl;
                    break;
                }
            }else{
                if(i == K - 1){
                    cout << tmp << endl;
                    break;
                }
            }
        }
        cnt++;
    }
    return 0;
}
0