結果

問題 No.22 括弧の対応
ユーザー Respect2D
提出日時 2014-11-21 01:00:28
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 408 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 56,336 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 06:55:12
合計ジャッジ時間 1,191 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int main(){
  int n, m;
  string s;

  while(cin >> n >> m >> s){
    int dir = 1;
    int level = 1;

    if(s[m - 1] == ')') dir = level = -1;

    int idx = m - 1;

    while(level != 0){
      idx += dir;
      if(s[idx] == '('){
        level++;
      }
      else{
        level--;
      }
    }

    cout << idx + 1 << endl;
  }
}
0