結果

問題 No.22 括弧の対応
ユーザー しんじ
提出日時 2025-01-20 22:06:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 722 bytes
コンパイル時間 1,505 ms
コンパイル使用メモリ 166,784 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2025-01-20 22:06:55
合計ジャッジ時間 2,447 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i,a,b) for(ll i = a; i < (ll)(b); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using VI = vector<int>;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int DX[] = {1,0,-1,0};
const int DY[] = {0,1,0,-1};

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	int n,k;
	string s;
	cin >> n >> k >> s;
	stack<int> st;
	
	k--;
	rep(i,n){
		if(s[i] == '('){
			st.push(i);
		}
		else{
			if(i == k){
				cout << st.top() + 1 << endl;
				return 0;
			}
			else {
				if(st.top() == k){
					cout << i+1 << endl;
					return 0;
				}
				st.pop();
			}
		}
	}
	return 0;
}
0