結果

問題 No.592 括弧の対応 (2)
ユーザー cormorancormoran
提出日時 2017-11-10 22:37:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 5,000 ms
コード長 587 bytes
コンパイル時間 1,699 ms
コンパイル使用メモリ 174,176 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 12:51:26
合計ジャッジ時間 3,113 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 274 ms
6,944 KB
testcase_02 AC 269 ms
6,940 KB
testcase_03 AC 270 ms
6,944 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