結果

問題 No.22 括弧の対応
ユーザー k
提出日時 2020-06-13 00:21:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 458 bytes
コンパイル時間 2,951 ms
コンパイル使用メモリ 197,356 KB
最終ジャッジ日時 2025-01-11 03:19:49
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, k;
  string s;
  cin >> n >> k >> s;

  vector<int> pr(n);
  stack<int> stk;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(')
      stk.push(i);
    else {
      int t = stk.top();
      stk.pop();
      pr[i] = t;
      pr[t] = i;
    }
  }

  cout << pr[k-1]+1 << endl;
  
  return 0;
}
0