結果

問題 No.592 括弧の対応 (2)
ユーザー ei1333333
提出日時 2017-11-10 22:22:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 283 ms / 5,000 ms
コード長 373 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 197,688 KB
最終ジャッジ日時 2025-01-05 03:55:28
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main()
{
  int N;
  string S;
  cin >> N;
  cin >> S;
  stack< int > st;
  int ans[200000];
  for(int i = 0; i < N; i++) {
    if(S[i] == '(') st.push(i);
    else {
      int p = st.top();
      st.pop();
      ans[i] = p;
      ans[p] = i;
    }
  }
  for(int i = 0; i < N; i++) {
    cout << ans[i] + 1 << endl;
  }
}
0