結果

問題 No.592 括弧の対応 (2)
ユーザー kosakkunkosakkun
提出日時 2017-11-10 22:24:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 5,000 ms
コード長 1,019 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 117,180 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 12:26:08
合計ジャッジ時間 2,158 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 246 ms
6,940 KB
testcase_02 AC 256 ms
6,944 KB
testcase_03 AC 243 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int N;
string S;
int ans[200010];

int main() {

    cin >> N >> S;
    
    stack < int > sta;

    REP(i,S.size()) {
        if (S[i] == '(') {
            sta.push(i + 1);
        } else {
            ans[sta.top()] = i + 1;
            ans[i + 1] = sta.top();
            sta.pop();
        }
    }

    for (int i = 1; i <= N; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}
0