101862024-03-29 11:15:40111Zárójelekcpp17Wrong answer 20/10017ms7928 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 0;
		}
		x+=y;
		ans.push_back(i);
	}
	for(int i:ans){
		cout<<i+1<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1700 KiB
2Accepted4ms2152 KiB
subtask20/11
3Accepted3ms2072 KiB
4Wrong answer3ms2308 KiB
5Wrong answer3ms2636 KiB
6Accepted3ms2580 KiB
7Accepted4ms3196 KiB
8Accepted4ms3144 KiB
subtask36/6
9Accepted4ms3236 KiB
10Accepted3ms3404 KiB
11Accepted3ms3708 KiB
subtask414/14
12Accepted4ms3820 KiB
13Accepted4ms3720 KiB
subtask50/23
14Wrong answer4ms3728 KiB
15Wrong answer3ms3584 KiB
subtask60/19
16Wrong answer4ms3528 KiB
17Wrong answer4ms3572 KiB
18Accepted4ms3852 KiB
19Wrong answer3ms4052 KiB
20Wrong answer3ms4256 KiB
21Wrong answer4ms4536 KiB
22Wrong answer3ms4632 KiB
23Wrong answer4ms4744 KiB
24Wrong answer3ms4840 KiB
subtask70/27
25Accepted4ms4740 KiB
26Wrong answer4ms4692 KiB
27Wrong answer4ms4864 KiB
28Wrong answer4ms4888 KiB
29Wrong answer7ms5200 KiB
30Wrong answer17ms7928 KiB
31Wrong answer4ms4768 KiB
32Wrong answer4ms4972 KiB
33Wrong answer4ms4748 KiB
34Wrong answer4ms4972 KiB
35Wrong answer3ms4540 KiB
36Wrong answer4ms5004 KiB
37Accepted3ms4536 KiB
38Wrong answer3ms4560 KiB
39Wrong answer8ms6320 KiB
40Wrong answer3ms4776 KiB
41Wrong answer3ms4704 KiB
42Accepted4ms4948 KiB
43Wrong answer3ms5012 KiB