結果

問題 No.592 括弧の対応 (2)
ユーザー CELICA
提出日時 2020-09-06 08:36:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 506 bytes
コンパイル時間 1,782 ms
コンパイル使用メモリ 173,064 KB
実行使用メモリ 7,128 KB
最終ジャッジ日時 2024-11-29 06:40:11
合計ジャッジ時間 2,863 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

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