結果

問題 No.592 括弧の対応 (2)
ユーザー legosuke
提出日時 2017-11-29 17:38:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 248 ms / 5,000 ms
コード長 416 bytes
コンパイル時間 1,121 ms
コンパイル使用メモリ 163,440 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-27 18:56:17
合計ジャッジ時間 2,664 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int n;
  string s;
  cin >> n >> s;

  int sz = s.size();
  stack<int> st;
  vector<int> ans(sz);
  for (int i = 0; i < sz; i++) {
    if (s[i] == '(') {
      st.push(i);
    } else {
      ans[i] = st.top() + 1;
      ans[st.top()] = i + 1;
      st.pop();
    }
  }

  for (int i = 0; i < sz; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}
0