101942024-03-29 11:42:49111Zárójelekcpp17Wrong answer 20/100600ms5136 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	vector<tuple<int,int,int>>v(N);
	int x=0;
	for(int i=0;i<N;i++){
		string S;
		cin>>S;
		int y=0,z=0;
		for(char c:S){
			if(c=='('){
				y++;
			}
			else{
				y--;
				z=min(z,y);
			}
		}
		x+=y;
		v[i]={z,y,i};
	}
	if(x!=0){
		cout<<-1<<'\n';
		return 0;
	}
	vector<int>ans;
	while(ans.size()<N){
		int bi=-1,by=-1e6;
		int dc=1;
		for(int i=0;i<v.size();i++){
			auto[z,y,_]=v[i];
			if(y>=0){
				dc=0;
			}
		}
		for(int i=0;i<v.size();i++){
			auto[z,y,_]=v[i];
			if(x+z>=0&&(dc?z>by:y>by)){
				bi=i;
				by=dc?z:y;
			}
		}
		if(bi==-1){
			cout<<-1<<'\n';
			return 0;
		}
		x+=get<1>(v[bi]);
		ans.push_back(get<2>(v[bi]));
		v.erase(v.begin()+bi);
	}
	for(int i:ans){
		cout<<i+1<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1704 KiB
2Accepted14ms2280 KiB
subtask20/11
3Accepted3ms2144 KiB
4Wrong answer3ms2380 KiB
5Wrong answer3ms2384 KiB
6Accepted3ms2508 KiB
7Accepted4ms3104 KiB
8Accepted4ms3064 KiB
subtask36/6
9Accepted14ms3036 KiB
10Accepted3ms2864 KiB
11Accepted3ms2868 KiB
subtask414/14
12Accepted14ms3076 KiB
13Accepted8ms3148 KiB
subtask50/23
14Wrong answer14ms3332 KiB
15Wrong answer8ms3580 KiB
subtask60/19
16Wrong answer4ms3664 KiB
17Wrong answer7ms3920 KiB
18Accepted14ms4056 KiB
19Wrong answer8ms3900 KiB
20Wrong answer8ms3796 KiB
21Wrong answer13ms3936 KiB
22Wrong answer13ms4068 KiB
23Wrong answer13ms4144 KiB
24Wrong answer13ms4272 KiB
subtask70/27
25Accepted4ms4316 KiB
26Wrong answer14ms4332 KiB
27Wrong answer28ms4392 KiB
28Wrong answer48ms4656 KiB
29Wrong answer284ms4932 KiB
30Time limit exceeded586ms4580 KiB
31Wrong answer46ms4508 KiB
32Wrong answer71ms4708 KiB
33Wrong answer27ms4392 KiB
34Wrong answer101ms4712 KiB
35Wrong answer6ms4400 KiB
36Wrong answer136ms5136 KiB
37Accepted4ms4676 KiB
38Wrong answer8ms4560 KiB
39Time limit exceeded600ms4264 KiB
40Wrong answer8ms4580 KiB
41Wrong answer3ms4516 KiB
42Wrong answer18ms4856 KiB
43Wrong answer13ms4936 KiB