101912024-03-29 11:40:04111Zárójelekcpp17Wrong answer 20/100600ms4672 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?y>by:y-z>by)){
				bi=i;
				by=dc?y:y-z;
			}
		}
		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
1Accepted3ms1824 KiB
2Accepted10ms2252 KiB
subtask20/11
3Accepted2ms2104 KiB
4Accepted3ms2228 KiB
5Accepted2ms2460 KiB
6Accepted3ms2516 KiB
7Wrong answer4ms3132 KiB
8Accepted4ms3116 KiB
subtask36/6
9Accepted9ms3220 KiB
10Accepted3ms3272 KiB
11Accepted3ms3232 KiB
subtask414/14
12Accepted9ms3536 KiB
13Accepted7ms3636 KiB
subtask50/23
14Wrong answer8ms3740 KiB
15Wrong answer7ms3860 KiB
subtask60/19
16Accepted4ms3668 KiB
17Accepted6ms3748 KiB
18Accepted10ms3892 KiB
19Wrong answer7ms3692 KiB
20Wrong answer7ms3948 KiB
21Wrong answer8ms4044 KiB
22Wrong answer8ms4176 KiB
23Wrong answer8ms4148 KiB
24Wrong answer8ms4060 KiB
subtask70/27
25Wrong answer4ms3952 KiB
26Wrong answer10ms4032 KiB
27Wrong answer18ms4080 KiB
28Wrong answer30ms4100 KiB
29Wrong answer172ms4672 KiB
30Time limit exceeded578ms4236 KiB
31Wrong answer28ms4120 KiB
32Wrong answer43ms4352 KiB
33Wrong answer17ms4096 KiB
34Wrong answer61ms4320 KiB
35Wrong answer4ms3884 KiB
36Wrong answer82ms4356 KiB
37Wrong answer4ms3884 KiB
38Wrong answer7ms3924 KiB
39Time limit exceeded600ms3736 KiB
40Wrong answer6ms3924 KiB
41Wrong answer3ms3844 KiB
42Accepted13ms4164 KiB
43Wrong answer8ms4072 KiB