結果
問題 | No.22 括弧の対応 |
ユーザー |
|
提出日時 | 2018-06-01 00:14:15 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 685 bytes |
コンパイル時間 | 1,409 ms |
コンパイル使用メモリ | 163,292 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:31:42 |
合計ジャッジ時間 | 2,139 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int n,k; string s; stack< pair<int,int> > st; cin >> n >> k >> s; for(int i=0;i<n;i++){ if(s[i]=='('){ if(i+1!=k) st.push(make_pair(0,i)); else st.push(make_pair(1,i)); } if(s[i]==')'){ if(i+1!=k){ if(st.top().first!=1){ st.pop(); } else{ cout << i+1 << endl; break; } } else{ cout << st.top().second+1 << endl; break; } } } return 0; }