結果

問題 No.22 括弧の対応
ユーザー h_noson
提出日時 2016-02-15 22:54:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 428 bytes
コンパイル時間 560 ms
コンパイル使用メモリ 61,916 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 07:09:07
合計ジャッジ時間 1,173 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stack>
using namespace std;

int main() {
    int n, k;
    stack<int> st;
    string s;
    cin >> n >> k >> s;
    int cor[n];
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(')
            st.push(i);
        else {
            int x = st.top();
            cor[x] = i;
            cor[i] = x;
            st.pop();
        }
    }
    cout << cor[k-1]+1 << endl;
    return 0;
}
0