結果

問題 No.592 括弧の対応 (2)
ユーザー ats5515ats5515
提出日時 2017-11-10 22:26:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 246 ms / 5,000 ms
コード長 678 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 77,712 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2023-08-16 02:57:56
合計ジャッジ時間 2,033 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 246 ms
6,568 KB
testcase_02 AC 233 ms
6,656 KB
testcase_03 AC 231 ms
6,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	string S;
	cin >> N;
	cin >> S;
	vector<int> A(N, -1);
	vector<int> res(N, -1);
	int cur = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '(') {
			A[cur] = i;
			cur++;
		}
		else {
			cur--;
			res[i] = A[cur];
		}
	}
	for (int i = 0; i < N; i++) {
		if (res[i] != -1) {
			res[res[i]] = i;
		}
	}
	for (int i = 0; i < N; i++) {
		cout << res[i] + 1 << endl;
	}
}
0