#include<bits/stdc++.h>
using namespace std;
struct z{
int b=0,r=0,id;
};
bool comp(z a, z b){
return a.r < b.r;
}
bool comp2(z a, z b){
return a.r > b.r;
}
int main(){
int n;
cin >> n;
vector<z> pos,neg;
for(int i = 1; i <= n; i++){
string s;
cin >> s;
z c;
c.id = i;
for(int j = 0; j < s.length(); j++){
if(s[j]=='('){
c.b++;
}else{
c.b--;
}
c.r = min(c.r, c.b);
}
c.r = abs(c.r);
if(c.b >= 0){
pos.push_back(c);
}else{
neg.push_back(c);
}
}
sort(pos.begin(), pos.end(), comp);
sort(neg.begin(), neg.end(), comp2);
int b=0;
vector<int> ans;
for(z i:pos){
if(i.r > b){
cout << -1;
return 0;
}
ans.push_back(i.id);
b+=i.b;
}
for(z i:neg){
if(i.r > b || b < 0){
cout << -1;
return 0;
}
ans.push_back(i.id);
b+=i.b;
}
if(b != 0){
cout << "-1";
return 0;
}
for(int i:ans){
cout << i << " ";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
2 | Accepted | 8ms | 2232 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Accepted | 3ms | 2380 KiB | ||||
4 | Wrong answer | 3ms | 2544 KiB | ||||
5 | Accepted | 3ms | 2752 KiB | ||||
6 | Accepted | 3ms | 2848 KiB | ||||
7 | Accepted | 8ms | 3440 KiB | ||||
8 | Accepted | 8ms | 3400 KiB | ||||
subtask3 | 6/6 | ||||||
9 | Accepted | 8ms | 3224 KiB | ||||
10 | Accepted | 8ms | 3220 KiB | ||||
11 | Accepted | 8ms | 3268 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 8ms | 3544 KiB | ||||
13 | Accepted | 8ms | 3760 KiB | ||||
subtask5 | 23/23 | ||||||
14 | Accepted | 8ms | 3756 KiB | ||||
15 | Accepted | 8ms | 4072 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Accepted | 7ms | 4004 KiB | ||||
17 | Accepted | 8ms | 4012 KiB | ||||
18 | Accepted | 8ms | 4028 KiB | ||||
19 | Accepted | 8ms | 4240 KiB | ||||
20 | Accepted | 8ms | 4236 KiB | ||||
21 | Wrong answer | 6ms | 4236 KiB | ||||
22 | Wrong answer | 6ms | 4508 KiB | ||||
23 | Wrong answer | 6ms | 4464 KiB | ||||
24 | Wrong answer | 6ms | 4416 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Accepted | 7ms | 4324 KiB | ||||
26 | Accepted | 8ms | 4364 KiB | ||||
27 | Accepted | 8ms | 4400 KiB | ||||
28 | Accepted | 8ms | 4416 KiB | ||||
29 | Accepted | 10ms | 4728 KiB | ||||
30 | Accepted | 24ms | 6396 KiB | ||||
31 | Accepted | 8ms | 4404 KiB | ||||
32 | Accepted | 9ms | 4564 KiB | ||||
33 | Accepted | 8ms | 4384 KiB | ||||
34 | Accepted | 9ms | 4576 KiB | ||||
35 | Accepted | 8ms | 4352 KiB | ||||
36 | Accepted | 10ms | 4828 KiB | ||||
37 | Accepted | 8ms | 4796 KiB | ||||
38 | Accepted | 8ms | 5016 KiB | ||||
39 | Accepted | 14ms | 5872 KiB | ||||
40 | Wrong answer | 4ms | 5016 KiB | ||||
41 | Wrong answer | 3ms | 4996 KiB | ||||
42 | Wrong answer | 7ms | 5196 KiB | ||||
43 | Wrong answer | 6ms | 5024 KiB |