5284 | 2023-04-25 11:09:28 | ZsofiaKeresztely | Zárójelek | cpp14 | Wrong answer 0/100 | 3ms | 4744 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
typedef long long ll;
int main()
{
freopen("be2.txt", "r", stdin);
int n;
cin >> n;
vector<pii> req(n+1);
vector<int> dif(n+1), op(n+1, 0), opp(n);
for (int i=1; i<=n; i++){
string s;
cin >> s;
int sum = 0;
int left=0, right=0, needed=0;
for (char c : s){
if (c == '(') left++;
else right++;
if (left + needed < right) needed++;
}
req[i] = make_pair(needed, i);
dif[i] = left - right;
}
req[0] = {0,0};
sort(req.begin(), req.end());
priority_queue<pii> pq;
int ind = 0, prov = 0, cnt = 1;
while (!req[ind+1].fi){
ind++;
pq.push({dif[req[ind].se], req[ind].se});
}
while (!pq.empty()){
pii p = pq.top();
pq.pop();
prov += p.fi;
op[p.se] = cnt;
cnt++;
while (ind < n && req[ind+1].fi <= prov){
ind++;
pq.push({dif[req[ind].se], req[ind].se});
}
while (ind > 0 && req[ind].fi > prov){
if (!op[req[ind].se]){
cout << -1;
return 0;
}
ind--;
}
}
for (int i=1; i<=n; i++){
if (!op[i]){
cout << -1;
return 0;
}
opp[op[i]-1] = i;
}
for (int x : opp){
cout << x << " ";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Wrong answer | 3ms | 1804 KiB | ||||
2 | Wrong answer | 3ms | 2068 KiB | ||||
subtask2 | 0/11 | ||||||
3 | Wrong answer | 3ms | 2280 KiB | ||||
4 | Wrong answer | 3ms | 2532 KiB | ||||
5 | Wrong answer | 3ms | 2796 KiB | ||||
6 | Wrong answer | 3ms | 3136 KiB | ||||
7 | Wrong answer | 3ms | 3192 KiB | ||||
8 | Wrong answer | 3ms | 3352 KiB | ||||
subtask3 | 0/6 | ||||||
9 | Wrong answer | 3ms | 3620 KiB | ||||
10 | Wrong answer | 2ms | 3600 KiB | ||||
11 | Wrong answer | 2ms | 3824 KiB | ||||
subtask4 | 0/14 | ||||||
12 | Wrong answer | 2ms | 3916 KiB | ||||
13 | Wrong answer | 2ms | 3808 KiB | ||||
subtask5 | 0/23 | ||||||
14 | Wrong answer | 2ms | 3976 KiB | ||||
15 | Wrong answer | 2ms | 3952 KiB | ||||
subtask6 | 0/19 | ||||||
16 | Wrong answer | 2ms | 3952 KiB | ||||
17 | Wrong answer | 2ms | 4080 KiB | ||||
18 | Wrong answer | 2ms | 4080 KiB | ||||
19 | Wrong answer | 2ms | 4116 KiB | ||||
20 | Wrong answer | 3ms | 4236 KiB | ||||
21 | Wrong answer | 3ms | 4224 KiB | ||||
22 | Wrong answer | 2ms | 4220 KiB | ||||
23 | Wrong answer | 3ms | 4348 KiB | ||||
24 | Wrong answer | 3ms | 4332 KiB | ||||
subtask7 | 0/27 | ||||||
25 | Wrong answer | 2ms | 4456 KiB | ||||
26 | Wrong answer | 3ms | 4432 KiB | ||||
27 | Wrong answer | 2ms | 4452 KiB | ||||
28 | Wrong answer | 2ms | 4552 KiB | ||||
29 | Wrong answer | 3ms | 4328 KiB | ||||
30 | Wrong answer | 2ms | 4324 KiB | ||||
31 | Wrong answer | 2ms | 4432 KiB | ||||
32 | Wrong answer | 2ms | 4324 KiB | ||||
33 | Wrong answer | 3ms | 4460 KiB | ||||
34 | Wrong answer | 3ms | 4532 KiB | ||||
35 | Wrong answer | 3ms | 4428 KiB | ||||
36 | Wrong answer | 2ms | 4428 KiB | ||||
37 | Wrong answer | 3ms | 4660 KiB | ||||
38 | Wrong answer | 2ms | 4636 KiB | ||||
39 | Wrong answer | 2ms | 4640 KiB | ||||
40 | Wrong answer | 2ms | 4640 KiB | ||||
41 | Wrong answer | 3ms | 4640 KiB | ||||
42 | Wrong answer | 2ms | 4744 KiB | ||||
43 | Wrong answer | 2ms | 4740 KiB |