結果

問題 No.22 括弧の対応
ユーザー ioryyyyz
提出日時 2015-07-24 07:48:05
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 618 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 165,300 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-08 12:49:42
合計ジャッジ時間 1,725 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;

    int first = 0;
    stack<pair<char, int>> stack;
    vector<int> pindex(N);
    stack.push(make_pair(s[first++], 0));
    while(!stack.empty()){
        if(s[first] == '('){
            stack.push(make_pair(s[first], first));
        } else if(s[first] == ')'){
            auto index = stack.top();
            stack.pop();
            pindex[first] = index.second;
            pindex[index.second] = first;
        }
        first++;
    }
    cout << pindex[K-1]+1 << endl;
    return 0;
}
0