#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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 4ms | 2408 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Accepted | 3ms | 2276 KiB | ||||
4 | Runtime error | 3ms | 2288 KiB | ||||
5 | Runtime error | 3ms | 2288 KiB | ||||
6 | Accepted | 3ms | 2412 KiB | ||||
7 | Accepted | 4ms | 2844 KiB | ||||
8 | Runtime error | 4ms | 3116 KiB | ||||
subtask3 | 6/6 | ||||||
9 | Accepted | 4ms | 3048 KiB | ||||
10 | Accepted | 3ms | 3048 KiB | ||||
11 | Accepted | 4ms | 3292 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 4ms | 3392 KiB | ||||
13 | Accepted | 4ms | 3784 KiB | ||||
subtask5 | 0/23 | ||||||
14 | Runtime error | 4ms | 3752 KiB | ||||
15 | Runtime error | 4ms | 3996 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Runtime error | 4ms | 3892 KiB | ||||
17 | Runtime error | 4ms | 4252 KiB | ||||
18 | Accepted | 4ms | 4368 KiB | ||||
19 | Runtime error | 3ms | 4288 KiB | ||||
20 | Runtime error | 3ms | 4296 KiB | ||||
21 | Runtime error | 3ms | 4432 KiB | ||||
22 | Runtime error | 3ms | 4512 KiB | ||||
23 | Runtime error | 3ms | 4524 KiB | ||||
24 | Runtime error | 4ms | 4724 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Runtime error | 4ms | 4880 KiB | ||||
26 | Runtime error | 4ms | 4888 KiB | ||||
27 | Runtime error | 4ms | 5184 KiB | ||||
28 | Runtime error | 4ms | 5176 KiB | ||||
29 | Runtime error | 7ms | 5608 KiB | ||||
30 | Runtime error | 17ms | 8348 KiB | ||||
31 | Runtime error | 4ms | 5188 KiB | ||||
32 | Runtime error | 4ms | 5444 KiB | ||||
33 | Runtime error | 4ms | 5192 KiB | ||||
34 | Runtime error | 4ms | 5360 KiB | ||||
35 | Runtime error | 3ms | 4932 KiB | ||||
36 | Runtime error | 4ms | 5396 KiB | ||||
37 | Runtime error | 3ms | 4924 KiB | ||||
38 | Runtime error | 3ms | 5092 KiB | ||||
39 | Runtime error | 8ms | 6604 KiB | ||||
40 | Runtime error | 3ms | 5060 KiB | ||||
41 | Runtime error | 3ms | 5000 KiB | ||||
42 | Accepted | 4ms | 5420 KiB | ||||
43 | Runtime error | 3ms | 5240 KiB |