#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;
for(int i=0;i<v.size();i++){
auto[z,y,_]=v[i];
if(x+z>=0&&y>by){
bi=i;
by=y;
}
}
if(bi==-1){
cout<<-1<<'\n';
cout<<ans.size()<<'\n';
return 1;
}
x+=by;
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 | Accepted | 10ms | 2244 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Accepted | 3ms | 2128 KiB | ||||
4 | Accepted | 3ms | 2336 KiB | ||||
5 | Runtime error | 2ms | 2416 KiB | ||||
6 | Accepted | 3ms | 2544 KiB | ||||
7 | Accepted | 4ms | 2888 KiB | ||||
8 | Runtime error | 4ms | 3164 KiB | ||||
subtask3 | 6/6 | ||||||
9 | Accepted | 9ms | 2924 KiB | ||||
10 | Accepted | 3ms | 2760 KiB | ||||
11 | Accepted | 3ms | 2892 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 9ms | 3216 KiB | ||||
13 | Accepted | 7ms | 3208 KiB | ||||
subtask5 | 0/23 | ||||||
14 | Runtime error | 9ms | 3288 KiB | ||||
15 | Runtime error | 7ms | 3148 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Runtime error | 4ms | 3092 KiB | ||||
17 | Runtime error | 6ms | 3124 KiB | ||||
18 | Accepted | 10ms | 3284 KiB | ||||
19 | Runtime error | 7ms | 3144 KiB | ||||
20 | Runtime error | 7ms | 3412 KiB | ||||
21 | Accepted | 9ms | 3512 KiB | ||||
22 | Accepted | 9ms | 3528 KiB | ||||
23 | Accepted | 9ms | 3740 KiB | ||||
24 | Accepted | 9ms | 3724 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Runtime error | 4ms | 3508 KiB | ||||
26 | Runtime error | 10ms | 3576 KiB | ||||
27 | Runtime error | 18ms | 3744 KiB | ||||
28 | Runtime error | 30ms | 3772 KiB | ||||
29 | Accepted | 174ms | 4316 KiB | ||||
30 | Time limit exceeded | 575ms | 3840 KiB | ||||
31 | Runtime error | 29ms | 3928 KiB | ||||
32 | Runtime error | 45ms | 4288 KiB | ||||
33 | Runtime error | 17ms | 4300 KiB | ||||
34 | Runtime error | 61ms | 4316 KiB | ||||
35 | Runtime error | 4ms | 3864 KiB | ||||
36 | Runtime error | 83ms | 4232 KiB | ||||
37 | Runtime error | 4ms | 3796 KiB | ||||
38 | Runtime error | 7ms | 3832 KiB | ||||
39 | Time limit exceeded | 560ms | 3580 KiB | ||||
40 | Accepted | 7ms | 3792 KiB | ||||
41 | Accepted | 3ms | 3720 KiB | ||||
42 | Accepted | 13ms | 4044 KiB | ||||
43 | Accepted | 9ms | 4180 KiB |