結果

問題 No.592 括弧の対応 (2)
ユーザー けーむけーむ
提出日時 2020-03-19 17:56:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 899 bytes
コンパイル時間 1,324 ms
コンパイル使用メモリ 169,176 KB
実行使用メモリ 5,472 KB
最終ジャッジ日時 2023-08-20 21:00:30
合計ジャッジ時間 2,137 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 19 ms
5,312 KB
testcase_02 AC 18 ms
5,472 KB
testcase_03 AC 17 ms
4,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    string s;
    cin >> s;
    stack<ll> idx;
    vector<ll> ans(n, -1);
    rep(i, n) {
        if (s[i] == '(') {
            idx.push(i);
        }
        else {
            ll v = idx.top(); idx.pop();
            ans[v] = i;
            ans[i] = v;
        }
    }
    rep(i, n) printf("%lld\n", ans[i] + 1);
    return 0;
}
0