結果

問題 No.592 括弧の対応 (2)
ユーザー CELICACELICA
提出日時 2020-09-06 08:36:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 506 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 171,520 KB
実行使用メモリ 6,932 KB
最終ジャッジ日時 2023-08-19 13:32:10
合計ジャッジ時間 2,716 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ul = unsigned long;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	string s;
	cin >> n >> s;

	vector<int> v(n);
	stack<int> st;
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == '(')
			st.push(i);
		else
		{
			int pos = st.top();
			v[i] = pos + 1;
			v[pos] = i + 1;
			st.pop();
		}
	}

	stringstream ss;
	for (const auto& it : v)
		ss << it << "\n";
	string res = ss.str();

	cout << res;

	return 0;
}
0