結果

問題 No.592 括弧の対応 (2)
ユーザー giusto_programgiusto_program
提出日時 2017-11-11 10:10:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 406 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 61,248 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 16:26:03
合計ジャッジ時間 1,914 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<stack>
using namespace std;

int n, cr[200005];
char c[200005];
stack<int> s;

int main() {
    cin >> n >> c;

    for (int i = 0; i < n; i++) {
        if (c[i] == '(') {
            s.push(i);
        }
        else {
            cr[i] = s.top();
            cr[s.top()] = i;

            s.pop();
        }
    }

    for (int i = 0; i < n; i++) cout << cr[i] + 1 << endl;
}
0