#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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Wrong answer | 10ms | 2288 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Accepted | 3ms | 2268 KiB | ||||
4 | Wrong answer | 3ms | 2488 KiB | ||||
5 | Wrong answer | 3ms | 2852 KiB | ||||
6 | Accepted | 3ms | 2908 KiB | ||||
7 | Accepted | 4ms | 3384 KiB | ||||
8 | Accepted | 4ms | 3736 KiB | ||||
subtask3 | 6/6 | ||||||
9 | Accepted | 9ms | 3488 KiB | ||||
10 | Accepted | 3ms | 3432 KiB | ||||
11 | Accepted | 4ms | 3684 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 9ms | 3972 KiB | ||||
13 | Accepted | 7ms | 4160 KiB | ||||
subtask5 | 0/23 | ||||||
14 | Wrong answer | 8ms | 4332 KiB | ||||
15 | Wrong answer | 7ms | 4164 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Accepted | 4ms | 4104 KiB | ||||
17 | Accepted | 6ms | 4144 KiB | ||||
18 | Wrong answer | 10ms | 4420 KiB | ||||
19 | Wrong answer | 7ms | 4428 KiB | ||||
20 | Wrong answer | 7ms | 4468 KiB | ||||
21 | Wrong answer | 8ms | 4724 KiB | ||||
22 | Wrong answer | 8ms | 4824 KiB | ||||
23 | Wrong answer | 8ms | 4692 KiB | ||||
24 | Wrong answer | 8ms | 4700 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Wrong answer | 4ms | 4484 KiB | ||||
26 | Wrong answer | 9ms | 4680 KiB | ||||
27 | Wrong answer | 17ms | 4720 KiB | ||||
28 | Wrong answer | 29ms | 4856 KiB | ||||
29 | Wrong answer | 261ms | 5272 KiB | ||||
30 | Time limit exceeded | 583ms | 4756 KiB | ||||
31 | Wrong answer | 27ms | 4656 KiB | ||||
32 | Wrong answer | 39ms | 4840 KiB | ||||
33 | Wrong answer | 16ms | 4748 KiB | ||||
34 | Wrong answer | 57ms | 4912 KiB | ||||
35 | Wrong answer | 4ms | 4780 KiB | ||||
36 | Wrong answer | 75ms | 5280 KiB | ||||
37 | Wrong answer | 4ms | 4672 KiB | ||||
38 | Wrong answer | 7ms | 4756 KiB | ||||
39 | Time limit exceeded | 600ms | 4412 KiB | ||||
40 | Wrong answer | 6ms | 5172 KiB | ||||
41 | Wrong answer | 3ms | 5008 KiB | ||||
42 | Wrong answer | 12ms | 5300 KiB | ||||
43 | Wrong answer | 8ms | 5244 KiB |