結果

問題 No.22 括弧の対応
ユーザー gemy
提出日時 2023-11-23 11:34:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 505 bytes
コンパイル時間 2,075 ms
コンパイル使用メモリ 197,880 KB
最終ジャッジ日時 2025-02-17 23:12:27
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
    // Input
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    // Simulation And Output
    --K;
    deque<int> p;
    rep(i, S.size()) {
        if (S[i] == '(') {
            p.push_back(i);
        } else {
            int j = p.back();
            p.pop_back();
            if (i == K) cout << j + 1 << endl;
            if (j == K) cout << i + 1 << endl;
        }
    }
}
0