結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
ty70
|
| 提出日時 | 2016-10-29 02:55:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 736 bytes |
| コンパイル時間 | 1,389 ms |
| コンパイル使用メモリ | 167,764 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:17:35 |
| 合計ジャッジ時間 | 1,961 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, K; cin >> N >> K;
string S; cin >> S;
stack<P> st;
vector<P> par; par.clear();
rep (i, N){
if (S[i] == '('){
st.push(P(i,-1));
}else{
P curr = st.top(); st.pop();
curr.second = i;
par.push_back(curr);
} // end if
} // end rep
int res = 0;
rep (i, par.size()){
if (K - 1 == par[i].first){
res = par[i].second + 1;
break;
} // end if
if (K - 1 == par[i].second){
res = par[i].first + 1;
break;
} // end if
} // end rep
cout << res << endl;
return 0;
}
ty70