結果

問題 No.592 括弧の対応 (2)
ユーザー masamasa
提出日時 2017-11-10 22:31:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 477 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 78,276 KB
実行使用メモリ 4,460 KB
最終ジャッジ日時 2023-08-16 03:05:42
合計ジャッジ時間 2,136 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>

using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;

	stack<int> st;

	vector<int> ans(n, -1); // 0-index
	for (int i = 0; i < n; i++) {
		if (s[i] == '(') {
			st.push(i);
		} else {
			int tmp = st.top();
			ans[tmp] = i;
			ans[i] = tmp;
			st.pop();
		}
	}

	for (auto x : ans) {
		cout << x + 1 << endl;
	}


	return 0;
}
0