結果

問題 No.22 括弧の対応
ユーザー GOTKAKO
提出日時 2025-05-12 19:43:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 421 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 198,260 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-05-12 19:43:09
合計ジャッジ時間 3,389 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,p; cin >> N >> p; p--;
    string s; cin >> s;
    vector<int> B(N);
    stack<int> St;
    for(int i=0; i<N; i++){
        if(s.at(i) == '(') St.push(i);
        else{
            B.at(St.top()) = i;
            B.at(i) = St.top(); St.pop();
        }
    }
    cout << B.at(p)+1 << endl;
}
0