結果
問題 | No.22 括弧の対応 |
ユーザー |
![]() |
提出日時 | 2015-05-15 11:17:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 531 bytes |
コンパイル時間 | 438 ms |
コンパイル使用メモリ | 57,984 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 07:00:52 |
合計ジャッジ時間 | 1,025 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <algorithm> #include <iostream> #include <string> using namespace::std; int main(void){ cin.tie(0); ios::sync_with_stdio(false); int N,K; cin >> N >> K; string str; cin >> str; int tab = 0; int ans = 0; if(str[K-1] == '('){ tab = 1; ans = K-1; while(tab!=0){ ++ans; if(str[ans]=='('){ ++tab; }else{ --tab; } } }else{ tab = -1; ans = K-1; while(tab!=0){ --ans; if(str[ans]=='('){ ++tab; }else{ --tab; } } } cout << ans + 1 << '\n'; return 0; }