結果

問題 No.592 括弧の対応 (2)
ユーザー cormorancormoran
提出日時 2017-11-10 22:37:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 5,000 ms
コード長 587 bytes
コンパイル時間 2,629 ms
コンパイル使用メモリ 171,144 KB
実行使用メモリ 4,496 KB
最終ジャッジ日時 2023-08-16 03:17:09
合計ジャッジ時間 3,527 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 256 ms
4,376 KB
testcase_02 AC 250 ms
4,496 KB
testcase_03 AC 253 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        string S; cin >> S;
        stack<int> stk;
        vector<int> res(N);
        rep(i, N) {
            if(S[i] == '(') stk.push(i);
            else {
                int p = stk.top(); stk.pop();
                res[p] = i + 1;
                res[i] = p + 1;
            }
        }
        rep(i, N) cout << res[i] << endl;
        return 0;
    }
};

int main() {
    Solver s;
    s.solve();
    return 0;
}
0