#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);
}
}
cout << -1;
return 0;
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 | Wrong answer | 3ms | 1812 KiB | ||||
2 | Wrong answer | 8ms | 2232 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Wrong answer | 3ms | 2328 KiB | ||||
4 | Wrong answer | 3ms | 2428 KiB | ||||
5 | Wrong answer | 3ms | 2536 KiB | ||||
6 | Wrong answer | 3ms | 2736 KiB | ||||
7 | Wrong answer | 7ms | 3072 KiB | ||||
8 | Accepted | 8ms | 3332 KiB | ||||
subtask3 | 0/6 | ||||||
9 | Wrong answer | 8ms | 3272 KiB | ||||
10 | Accepted | 8ms | 3532 KiB | ||||
11 | Accepted | 8ms | 3764 KiB | ||||
subtask4 | 0/14 | ||||||
12 | Wrong answer | 8ms | 3744 KiB | ||||
13 | Wrong answer | 8ms | 3724 KiB | ||||
subtask5 | 0/23 | ||||||
14 | Wrong answer | 8ms | 4072 KiB | ||||
15 | Wrong answer | 8ms | 4012 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Wrong answer | 7ms | 4072 KiB | ||||
17 | Wrong answer | 8ms | 4212 KiB | ||||
18 | Wrong answer | 8ms | 4240 KiB | ||||
19 | Wrong answer | 8ms | 4148 KiB | ||||
20 | Wrong answer | 8ms | 4152 KiB | ||||
21 | Wrong answer | 6ms | 4448 KiB | ||||
22 | Wrong answer | 6ms | 4404 KiB | ||||
23 | Wrong answer | 6ms | 4408 KiB | ||||
24 | Wrong answer | 6ms | 4444 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Accepted | 7ms | 4412 KiB | ||||
26 | Wrong answer | 8ms | 4396 KiB | ||||
27 | Wrong answer | 8ms | 4644 KiB | ||||
28 | Wrong answer | 8ms | 4616 KiB | ||||
29 | Wrong answer | 8ms | 4828 KiB | ||||
30 | Wrong answer | 14ms | 6236 KiB | ||||
31 | Wrong answer | 8ms | 4744 KiB | ||||
32 | Wrong answer | 8ms | 4892 KiB | ||||
33 | Wrong answer | 8ms | 5044 KiB | ||||
34 | Wrong answer | 8ms | 5196 KiB | ||||
35 | Wrong answer | 8ms | 4976 KiB | ||||
36 | Wrong answer | 8ms | 5196 KiB | ||||
37 | Accepted | 8ms | 4976 KiB | ||||
38 | Wrong answer | 8ms | 5068 KiB | ||||
39 | Wrong answer | 10ms | 5752 KiB | ||||
40 | Wrong answer | 4ms | 5016 KiB | ||||
41 | Wrong answer | 3ms | 4964 KiB | ||||
42 | Wrong answer | 7ms | 5184 KiB | ||||
43 | Wrong answer | 6ms | 5156 KiB |