101932024-03-29 11:41:57111Zárójelekcpp17Wrong answer 20/100564ms5288 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<2>(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
1Accepted3ms1696 KiB
2Accepted14ms2220 KiB
subtask20/11
3Accepted3ms2148 KiB
4Wrong answer3ms2356 KiB
5Wrong answer3ms2528 KiB
6Accepted3ms2740 KiB
7Wrong answer4ms3352 KiB
8Accepted4ms3520 KiB
subtask36/6
9Accepted14ms3564 KiB
10Accepted3ms3380 KiB
11Accepted3ms3380 KiB
subtask414/14
12Accepted14ms3556 KiB
13Accepted8ms3400 KiB
subtask50/23
14Wrong answer14ms3536 KiB
15Wrong answer8ms3652 KiB
subtask60/19
16Wrong answer4ms3476 KiB
17Wrong answer7ms3516 KiB
18Accepted14ms3848 KiB
19Wrong answer8ms3816 KiB
20Wrong answer8ms3816 KiB
21Wrong answer13ms3948 KiB
22Wrong answer13ms3868 KiB
23Wrong answer13ms3992 KiB
24Wrong answer13ms4084 KiB
subtask70/27
25Wrong answer4ms3832 KiB
26Wrong answer14ms4024 KiB
27Wrong answer29ms4452 KiB
28Wrong answer48ms4552 KiB
29Wrong answer284ms5288 KiB
30Time limit exceeded564ms4936 KiB
31Wrong answer46ms4620 KiB
32Wrong answer71ms4988 KiB
33Wrong answer28ms4776 KiB
34Wrong answer101ms5000 KiB
35Wrong answer6ms4608 KiB
36Wrong answer136ms5068 KiB
37Wrong answer4ms4736 KiB
38Wrong answer8ms4768 KiB
39Time limit exceeded535ms4424 KiB
40Wrong answer8ms4748 KiB
41Wrong answer4ms4920 KiB
42Wrong answer18ms5116 KiB
43Wrong answer13ms5100 KiB