101882024-03-29 11:27:13111Zárójelekcpp17Runtime error 20/100575ms4316 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';
			cout<<ans.size()<<'\n';
			return 1;
		}
		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
1Accepted3ms1824 KiB
2Accepted10ms2244 KiB
subtask20/11
3Accepted3ms2128 KiB
4Accepted3ms2336 KiB
5Runtime error2ms2416 KiB
6Accepted3ms2544 KiB
7Accepted4ms2888 KiB
8Runtime error4ms3164 KiB
subtask36/6
9Accepted9ms2924 KiB
10Accepted3ms2760 KiB
11Accepted3ms2892 KiB
subtask414/14
12Accepted9ms3216 KiB
13Accepted7ms3208 KiB
subtask50/23
14Runtime error9ms3288 KiB
15Runtime error7ms3148 KiB
subtask60/19
16Runtime error4ms3092 KiB
17Runtime error6ms3124 KiB
18Accepted10ms3284 KiB
19Runtime error7ms3144 KiB
20Runtime error7ms3412 KiB
21Accepted9ms3512 KiB
22Accepted9ms3528 KiB
23Accepted9ms3740 KiB
24Accepted9ms3724 KiB
subtask70/27
25Runtime error4ms3508 KiB
26Runtime error10ms3576 KiB
27Runtime error18ms3744 KiB
28Runtime error30ms3772 KiB
29Accepted174ms4316 KiB
30Time limit exceeded575ms3840 KiB
31Runtime error29ms3928 KiB
32Runtime error45ms4288 KiB
33Runtime error17ms4300 KiB
34Runtime error61ms4316 KiB
35Runtime error4ms3864 KiB
36Runtime error83ms4232 KiB
37Runtime error4ms3796 KiB
38Runtime error7ms3832 KiB
39Time limit exceeded560ms3580 KiB
40Accepted7ms3792 KiB
41Accepted3ms3720 KiB
42Accepted13ms4044 KiB
43Accepted9ms4180 KiB