101892024-03-29 11:28:00111Zárójelekcpp17Wrong answer 20/100574ms5320 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;
		for(int i=0;i<v.size();i++){
			auto[z,y,_]=v[i];
			if(x+z>=0&&y>by){
				bi=i;
				by=y;
			}
		}
		if(bi==-1){
			cout<<-1<<'\n';
			return 0;
		}
		x+=by;
		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
1Accepted3ms1828 KiB
2Accepted10ms2280 KiB
subtask20/11
3Accepted3ms2264 KiB
4Accepted3ms2444 KiB
5Wrong answer3ms2656 KiB
6Accepted3ms2884 KiB
7Accepted4ms3480 KiB
8Accepted4ms3692 KiB
subtask36/6
9Accepted9ms3744 KiB
10Accepted3ms3616 KiB
11Accepted3ms3768 KiB
subtask414/14
12Accepted9ms3892 KiB
13Accepted7ms3756 KiB
subtask50/23
14Wrong answer9ms3908 KiB
15Wrong answer7ms3824 KiB
subtask60/19
16Wrong answer4ms3768 KiB
17Wrong answer6ms3864 KiB
18Accepted10ms4024 KiB
19Wrong answer7ms3852 KiB
20Wrong answer7ms4108 KiB
21Accepted9ms4216 KiB
22Accepted9ms4220 KiB
23Accepted9ms4212 KiB
24Accepted9ms4216 KiB
subtask70/27
25Accepted4ms4104 KiB
26Wrong answer10ms4140 KiB
27Wrong answer19ms4440 KiB
28Wrong answer32ms4808 KiB
29Accepted174ms5320 KiB
30Time limit exceeded569ms4884 KiB
31Wrong answer29ms4776 KiB
32Wrong answer45ms5024 KiB
33Wrong answer17ms5016 KiB
34Wrong answer63ms5248 KiB
35Wrong answer4ms4884 KiB
36Wrong answer83ms5308 KiB
37Accepted4ms5148 KiB
38Wrong answer7ms5128 KiB
39Time limit exceeded574ms4948 KiB
40Accepted7ms5108 KiB
41Accepted3ms5020 KiB
42Accepted13ms5264 KiB
43Accepted9ms5292 KiB