結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
cww
|
| 提出日時 | 2016-09-15 01:58:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 725 bytes |
| コンパイル時間 | 2,237 ms |
| コンパイル使用メモリ | 174,168 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 07:16:39 |
| 合計ジャッジ時間 | 2,578 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(n); i++)
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
//pairで対応する括弧のindexを保持していくversion
int main()
{
int N, K;
string S;
cin >> N >> K >> S;
vector<pair<int, int>> P;
stack<int> st;
REP( i, (int)S.size() )
{
if( S[i] == '(' )
{
st.emplace( i );
continue;
}
//Lに'('のindex, Rに')'のindexを入れる
int L = st.top() + 1;
int R = i + 1;
P.emplace_back( make_pair( L, R ) );
st.pop();
}
for( auto &x : P )
{
if( x.first == K )
{
cout << x.second << endl;
break;
}
if( x.second == K )
{
cout << x.first << endl;
break;
}
}
return 0;
}
cww