101872024-03-29 11:16:34111Zárójelekcpp17Runtime error 20/10017ms8348 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;
	}
	sort(v.rbegin(),v.rend());
	vector<int>ans;
	for(auto[z,y,i]:v){
		if(x+z<0){
			cout<<-1<<'\n';
			return 1;
		}
		x+=y;
		ans.push_back(i);
	}
	for(int i:ans){
		cout<<i+1<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted4ms2408 KiB
subtask20/11
3Accepted3ms2276 KiB
4Runtime error3ms2288 KiB
5Runtime error3ms2288 KiB
6Accepted3ms2412 KiB
7Accepted4ms2844 KiB
8Runtime error4ms3116 KiB
subtask36/6
9Accepted4ms3048 KiB
10Accepted3ms3048 KiB
11Accepted4ms3292 KiB
subtask414/14
12Accepted4ms3392 KiB
13Accepted4ms3784 KiB
subtask50/23
14Runtime error4ms3752 KiB
15Runtime error4ms3996 KiB
subtask60/19
16Runtime error4ms3892 KiB
17Runtime error4ms4252 KiB
18Accepted4ms4368 KiB
19Runtime error3ms4288 KiB
20Runtime error3ms4296 KiB
21Runtime error3ms4432 KiB
22Runtime error3ms4512 KiB
23Runtime error3ms4524 KiB
24Runtime error4ms4724 KiB
subtask70/27
25Runtime error4ms4880 KiB
26Runtime error4ms4888 KiB
27Runtime error4ms5184 KiB
28Runtime error4ms5176 KiB
29Runtime error7ms5608 KiB
30Runtime error17ms8348 KiB
31Runtime error4ms5188 KiB
32Runtime error4ms5444 KiB
33Runtime error4ms5192 KiB
34Runtime error4ms5360 KiB
35Runtime error3ms4932 KiB
36Runtime error4ms5396 KiB
37Runtime error3ms4924 KiB
38Runtime error3ms5092 KiB
39Runtime error8ms6604 KiB
40Runtime error3ms5060 KiB
41Runtime error3ms5000 KiB
42Accepted4ms5420 KiB
43Runtime error3ms5240 KiB