結果

問題 No.22 括弧の対応
ユーザー 古寺いろは
提出日時 2015-04-15 22:24:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 333 bytes
コンパイル時間 1,406 ms
コンパイル使用メモリ 163,532 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 06:59:35
合計ジャッジ時間 2,131 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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



int main() {
	int N, K;
	string S;
	cin >> N >> K;
	cin >> S;
	vector<int> dp(N);
	stack<int> st;
	for (int i = 0; i < N; i++)
	{
		if (S[i] == '('){
			st.push(i);
		}
		else{
			int num = st.top(); st.pop();
			dp[i] = num;
			dp[num] = i;
		}
	}
	cout << dp[K - 1] + 1 << endl;
}

0