結果

問題 No.592 括弧の対応 (2)
ユーザー kosakkunkosakkun
提出日時 2017-11-10 22:24:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 5,000 ms
コード長 1,019 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 115,616 KB
実行使用メモリ 4,520 KB
最終ジャッジ日時 2023-08-16 02:47:32
合計ジャッジ時間 2,242 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 242 ms
4,380 KB
testcase_02 AC 243 ms
4,520 KB
testcase_03 AC 246 ms
4,376 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