結果

問題 No.592 括弧の対応 (2)
ユーザー sggkshiosggkshio
提出日時 2018-04-01 12:08:33
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 741 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 81,360 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 11:23:35
合計ジャッジ時間 8,127 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

//#include<bits/stdc++.h>

int f[2000005];
int main() {
	
	int n;
	string p;
	cin >> n >> p;
	for (int i = 0; i < n; i++) {
		if (p[i]==')'||f[i])continue;
		int x = 0;
		for (int j = i + 1; j < n; j++) {
			if (p[j] == ')') {
				if (!x) { f[i] = j + 1; f[j] = i + 1; break; }
				else x--;
			}
			else x++;
		}
	}
	for (int i = 0; i < n; i++)
		cout << f[i] << endl;

	return 0;
}
0