結果

問題 No.592 括弧の対応 (2)
ユーザー 0x19f0x19f
提出日時 2017-11-10 22:42:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 244 ms / 5,000 ms
コード長 403 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 148,988 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2023-08-16 03:22:58
合計ジャッジ時間 2,515 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 244 ms
5,296 KB
testcase_02 AC 242 ms
5,632 KB
testcase_03 AC 240 ms
5,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll N;
string S;

int main(void) {
  cin >> N >> S;

  vector<ll> ans(N);
  stack<ll> stk;
  REP(i, 0, N) {
    if(S[i] == '(') stk.push(i);
    else {
      ans[i] = stk.top();
      ans[ans[i]] = i;
      stk.pop();
    }
  }

  REP(i, 0, N) cout << ans[i] + 1 << endl;
}
0