結果

問題 No.592 括弧の対応 (2)
ユーザー square1001square1001
提出日時 2017-11-10 23:12:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 362 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 71,544 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 14:26:17
合計ジャッジ時間 1,229 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 23 ms
6,944 KB
testcase_02 AC 22 ms
6,940 KB
testcase_03 AC 21 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stack>
#include <string>
#include <iostream>
using namespace std;
int n, ans[200009]; string s;
int main() {
	cin >> n >> s;
	stack<int> st;
	for (int i = 0; i < n; i++) {
		if (s[i] == '(') st.push(i);
		else {
			int v = st.top();
			st.pop();
			ans[i] = v;
			ans[v] = i;
		}
	}
	for (int i = 0; i < n; i++) cout << ans[i] + 1 << '\n';
	return 0;
}
0