結果

問題 No.22 括弧の対応
ユーザー hiyori
提出日時 2016-09-18 21:03:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 535 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 56,988 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-17 09:03:28
合計ジャッジ時間 1,170 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int main ()
{
  int N, K;
  string s;
  cin >> N >> K >> s;

  int n = K;

  if  (s[K] == '(') {
    int cnt = 1;
    for (int i = K+1; i <= N; i++) {
      if (s[i] == '(') cnt++;
      else cnt--;
      if (cnt == 0) {
        cout << i-K << endl;
        break;
      }
    }
  }
  else {
    int cnt = -1;
    for (int i = K+1; i >= 1; i--) {
      if (s[i] == ')') cnt--;
      else cnt++;
      if (cnt == 0) {
        cout << i-K << endl;
        break;
      }
    }
  }
  return 0;
}
0