結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2018-03-06 16:54:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 719 bytes |
コンパイル時間 | 554 ms |
コンパイル使用メモリ | 81,072 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:29:48 |
合計ジャッジ時間 | 1,178 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<iomanip> #include<cstring> #include<map> #include<vector> #include<queue> #include<utility> using namespace std; typedef long long int ll; int main(){ int n, k, l=0, r=0; string s; cin >> n >> k; cin >> s; if(s[k-1]=='('){ l++; for(int i=k; i<n; i++){ if(s[i]=='('){ l++; } else { r++; } if(l==r){ cout << i+1 << endl; return 0; } } } else { r++; for(int i=k-2; 0<=i; i--){ if(s[i]=='('){ l++; } else { r++; } if(l==r){ cout << i+1 << endl; return 0; } } } return 0; }