結果

問題 No.592 括弧の対応 (2)
ユーザー treeonetreeone
提出日時 2017-11-10 22:28:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 250 ms / 5,000 ms
コード長 1,081 bytes
コンパイル時間 1,742 ms
コンパイル使用メモリ 149,184 KB
実行使用メモリ 11,696 KB
最終ジャッジ日時 2023-08-16 03:02:50
合計ジャッジ時間 3,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,780 KB
testcase_01 AC 250 ms
11,368 KB
testcase_02 AC 246 ms
11,696 KB
testcase_03 AC 233 ms
10,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

vector<int> d[100010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int now = 0;
    vector<P> id(n);
    rep(i, 0, n){
        if(s[i] == '('){
            id[i].first = now;
            id[i].second = d[now].size();
            d[now].push_back(i);
            now++;
        }else{
            now--;
            id[i].first = now;
            id[i].second = d[now].size();
            d[now].push_back(i);
        }
    }
    rep(i, 0, n){
        if(id[i].second % 2){
            cout << d[id[i].first][id[i].second - 1] + 1 << endl;
        }else{
            cout << d[id[i].first][id[i].second + 1] + 1<< endl;
        }
    }
}
0