結果

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

ソースコード

diff #

#include <iostream>
#include <sstream>
#include <vector>
#include <stack>
#include <cmath>
using namespace std;
# define M_PI 3.14159265358979323846

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    string str;
    cin >> str;
    stack<int> s;
    vector<int> ans(n);
    for(int i = 0; i < n; i++){
    	char tmp = str[i];
    	if(tmp == '('){
    		s.push(i);
    	} else {
    		int pop = s.top();
    		s.pop();
    		ans[pop] = i;
    		ans[i] = pop;
    	}
    }
    
    cout << ans[k-1]+1 << endl;
    
    return 0;
}
0