結果

問題 No.22 括弧の対応
ユーザー hiyorihiyori
提出日時 2016-09-18 19:55:03
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 496 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 55,436 KB
実行使用メモリ 10,140 KB
最終ジャッジ日時 2024-04-28 15:38:32
合計ジャッジ時間 7,092 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REP2(i, a, b) for (int i = a; i <= b; i++)
using namespace std;

int main ()
{
  int N, K;
  cin >> N >> K;
  char str[10000+1];

  REP2 (i, 1, N) cin >> str[i];

  int cnt = 0;
  int n = K;
  for (;;) {
    if (str[n] == '(') {
      cnt++;
    }
    else {  // K番目の括弧が')'の時
      cnt--;
    }
    if (cnt == 0) {
      cout << n << endl;
      return 0;
    }
    if (n == N) n = 1;
  }
  return 0;
}
0