101902024-03-29 11:39:25111Zárójelekcpp17Wrong answer 20/100600ms5300 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>by:y-z>by;
			}
		}
		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
2Wrong answer10ms2288 KiB
subtask20/11
3Accepted3ms2268 KiB
4Wrong answer3ms2488 KiB
5Wrong answer3ms2852 KiB
6Accepted3ms2908 KiB
7Accepted4ms3384 KiB
8Accepted4ms3736 KiB
subtask36/6
9Accepted9ms3488 KiB
10Accepted3ms3432 KiB
11Accepted4ms3684 KiB
subtask414/14
12Accepted9ms3972 KiB
13Accepted7ms4160 KiB
subtask50/23
14Wrong answer8ms4332 KiB
15Wrong answer7ms4164 KiB
subtask60/19
16Accepted4ms4104 KiB
17Accepted6ms4144 KiB
18Wrong answer10ms4420 KiB
19Wrong answer7ms4428 KiB
20Wrong answer7ms4468 KiB
21Wrong answer8ms4724 KiB
22Wrong answer8ms4824 KiB
23Wrong answer8ms4692 KiB
24Wrong answer8ms4700 KiB
subtask70/27
25Wrong answer4ms4484 KiB
26Wrong answer9ms4680 KiB
27Wrong answer17ms4720 KiB
28Wrong answer29ms4856 KiB
29Wrong answer261ms5272 KiB
30Time limit exceeded583ms4756 KiB
31Wrong answer27ms4656 KiB
32Wrong answer39ms4840 KiB
33Wrong answer16ms4748 KiB
34Wrong answer57ms4912 KiB
35Wrong answer4ms4780 KiB
36Wrong answer75ms5280 KiB
37Wrong answer4ms4672 KiB
38Wrong answer7ms4756 KiB
39Time limit exceeded600ms4412 KiB
40Wrong answer6ms5172 KiB
41Wrong answer3ms5008 KiB
42Wrong answer12ms5300 KiB
43Wrong answer8ms5244 KiB