結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
int main(){
  int N;
  string s;
  cin >> N;
  cin >> s;
  vector<int> ans(N);
  stack<int> st;

  for(int i = 0;i < N;i++){
    char c = s[i];
    if(c == '('){
      st.push(i);
    }
    else{
      int j = st.top();
      st.pop();
      ans[j] = i;
      ans[i] = j;
    }
  }

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