#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
vector<pair<int, pair<int,int>>> sortedVec(n);
for (int i = 0; i < n; i++)
{
int minC = 0;
int totalProfit = 0;
string s;
cin >> s;
for (size_t j = 0; j < s.size(); j++)
{
if (s[j] == '(') {
totalProfit++;
}
else {
totalProfit--;
minC = min(minC, totalProfit);
}
}
sortedVec[i] = { minC, {totalProfit, i } };
}
std::sort(sortedVec.begin(), sortedVec.end());
std::reverse(sortedVec.begin(), sortedVec.end());
int profit = 0;
vector<int> res;
for (size_t i = 0; i < n; i++)
{
if (profit >= sortedVec[i].first) {
profit += sortedVec[i].second.first;
res.push_back(sortedVec[i].second.second);
}
else {
cout << "-1";
break;
}
}
for (size_t i = 0; i < res.size(); i++)
{
cout << res[i]+1 << " ";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1940 KiB | ||||
2 | Accepted | 8ms | 2484 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Accepted | 3ms | 2660 KiB | ||||
4 | Wrong answer | 3ms | 2660 KiB | ||||
5 | Wrong answer | 3ms | 2844 KiB | ||||
6 | Accepted | 3ms | 3060 KiB | ||||
7 | Accepted | 8ms | 3912 KiB | ||||
8 | Wrong answer | 8ms | 4216 KiB | ||||
subtask3 | 0/6 | ||||||
9 | Accepted | 8ms | 4032 KiB | ||||
10 | Wrong answer | 8ms | 4360 KiB | ||||
11 | Wrong answer | 8ms | 4452 KiB | ||||
subtask4 | 14/14 | ||||||
12 | Accepted | 8ms | 4904 KiB | ||||
13 | Accepted | 8ms | 5300 KiB | ||||
subtask5 | 0/23 | ||||||
14 | Wrong answer | 8ms | 5624 KiB | ||||
15 | Wrong answer | 8ms | 5800 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Wrong answer | 8ms | 6004 KiB | ||||
17 | Wrong answer | 8ms | 6212 KiB | ||||
18 | Accepted | 8ms | 6696 KiB | ||||
19 | Wrong answer | 8ms | 7064 KiB | ||||
20 | Wrong answer | 8ms | 7176 KiB | ||||
21 | Wrong answer | 6ms | 7628 KiB | ||||
22 | Wrong answer | 6ms | 7920 KiB | ||||
23 | Wrong answer | 6ms | 8008 KiB | ||||
24 | Wrong answer | 6ms | 7976 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Wrong answer | 8ms | 8052 KiB | ||||
26 | Wrong answer | 8ms | 8340 KiB | ||||
27 | Wrong answer | 9ms | 8696 KiB | ||||
28 | Wrong answer | 9ms | 9016 KiB | ||||
29 | Wrong answer | 13ms | 9572 KiB | ||||
30 | Wrong answer | 29ms | 11180 KiB | ||||
31 | Wrong answer | 8ms | 9764 KiB | ||||
32 | Wrong answer | 8ms | 10000 KiB | ||||
33 | Wrong answer | 8ms | 10160 KiB | ||||
34 | Wrong answer | 9ms | 10424 KiB | ||||
35 | Wrong answer | 7ms | 10392 KiB | ||||
36 | Wrong answer | 9ms | 10844 KiB | ||||
37 | Wrong answer | 8ms | 11060 KiB | ||||
38 | Wrong answer | 8ms | 11232 KiB | ||||
39 | Wrong answer | 16ms | 12308 KiB | ||||
40 | Wrong answer | 4ms | 11940 KiB | ||||
41 | Wrong answer | 3ms | 11832 KiB | ||||
42 | Accepted | 7ms | 12216 KiB | ||||
43 | Wrong answer | 6ms | 12456 KiB |