結果
| 問題 | 
                            No.22 括弧の対応
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2018-02-04 05:47:50 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 519 bytes | 
| コンパイル時間 | 2,108 ms | 
| コンパイル使用メモリ | 171,860 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-20 07:29:11 | 
| 合計ジャッジ時間 | 2,079 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    string s;
    cin >> n >> k >> s;
    stack<int> st;
    vector<int> a(n);
    REP(i, n) {
        if (s[i] == '(') {
            st.push(i);
        } else {
            int cnt = st.top();
            st.pop();
            a[i] = cnt;
            a[cnt] = i;
        }
    }
    cout << a[k - 1] + 1 << endl;
    return 0;
}