結果

問題 No.22 括弧の対応
コンテスト
ユーザー KKT89
提出日時 2020-03-16 00:57:47
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 5,000 ms
+ 940µs
コード長 632 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 776 ms
コンパイル使用メモリ 139,012 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-11-10 21:08:41
合計ジャッジ時間 2,309 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <map>
#include <queue>
#include <cstring>
#include <set>
#include <stack>
using namespace std;
typedef long long int ll;

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