結果

問題 No.592 括弧の対応 (2)
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-03-20 00:16:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 270 ms / 5,000 ms
コード長 603 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 67,668 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-10-12 16:00:36
合計ジャッジ時間 2,708 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
#define MOD 1000000007
using namespace std;

int main(){
    int N;
    string S;
    cin >> N >> S;
    stack<int> sta;
    vector<int> v(N);
    for(int i = 0; i < N; i++)
    {
        if (S[i] == '(') {
            sta.push(i);
        }
        else {
            int c = sta.top();
            sta.pop();
            v[c] = i+1;
            v[i] = c+1;
        }
    }
    for(int i = 0; i < N; i++)
    {
        cout << v[i] << endl;
    }
    
    return 0;
}
0