101922024-03-29 11:40:51111Zárójelekcpp17Wrong answer 20/100600ms5544 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-z>by:y>by)){
				bi=i;
				by=dc?y-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
1Accepted3ms1828 KiB
2Accepted13ms2248 KiB
subtask20/11
3Accepted3ms2100 KiB
4Accepted3ms2232 KiB
5Accepted3ms2444 KiB
6Accepted3ms2656 KiB
7Wrong answer4ms2996 KiB
8Accepted4ms3252 KiB
subtask36/6
9Accepted12ms3304 KiB
10Accepted3ms3264 KiB
11Accepted3ms3540 KiB
subtask414/14
12Accepted12ms3548 KiB
13Accepted8ms3660 KiB
subtask50/23
14Wrong answer12ms3888 KiB
15Wrong answer8ms3828 KiB
subtask60/19
16Accepted4ms4020 KiB
17Accepted6ms4276 KiB
18Accepted13ms4384 KiB
19Wrong answer8ms4248 KiB
20Wrong answer8ms4388 KiB
21Wrong answer10ms4524 KiB
22Wrong answer9ms4616 KiB
23Wrong answer9ms4672 KiB
24Wrong answer9ms4924 KiB
subtask70/27
25Wrong answer4ms4676 KiB
26Accepted13ms4872 KiB
27Accepted25ms5064 KiB
28Accepted41ms4940 KiB
29Accepted233ms5544 KiB
30Time limit exceeded580ms5240 KiB
31Wrong answer37ms5240 KiB
32Wrong answer57ms5288 KiB
33Wrong answer23ms5164 KiB
34Wrong answer82ms5456 KiB
35Wrong answer4ms4936 KiB
36Wrong answer111ms5392 KiB
37Wrong answer4ms4920 KiB
38Wrong answer8ms4952 KiB
39Time limit exceeded600ms4640 KiB
40Wrong answer7ms4952 KiB
41Wrong answer3ms5144 KiB
42Accepted14ms5332 KiB
43Wrong answer9ms5412 KiB