52842023-04-25 11:09:28ZsofiaKeresztelyZárójelekcpp14Wrong answer 0/1003ms4744 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 << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1804 KiB
2Wrong answer3ms2068 KiB
subtask20/11
3Wrong answer3ms2280 KiB
4Wrong answer3ms2532 KiB
5Wrong answer3ms2796 KiB
6Wrong answer3ms3136 KiB
7Wrong answer3ms3192 KiB
8Wrong answer3ms3352 KiB
subtask30/6
9Wrong answer3ms3620 KiB
10Wrong answer2ms3600 KiB
11Wrong answer2ms3824 KiB
subtask40/14
12Wrong answer2ms3916 KiB
13Wrong answer2ms3808 KiB
subtask50/23
14Wrong answer2ms3976 KiB
15Wrong answer2ms3952 KiB
subtask60/19
16Wrong answer2ms3952 KiB
17Wrong answer2ms4080 KiB
18Wrong answer2ms4080 KiB
19Wrong answer2ms4116 KiB
20Wrong answer3ms4236 KiB
21Wrong answer3ms4224 KiB
22Wrong answer2ms4220 KiB
23Wrong answer3ms4348 KiB
24Wrong answer3ms4332 KiB
subtask70/27
25Wrong answer2ms4456 KiB
26Wrong answer3ms4432 KiB
27Wrong answer2ms4452 KiB
28Wrong answer2ms4552 KiB
29Wrong answer3ms4328 KiB
30Wrong answer2ms4324 KiB
31Wrong answer2ms4432 KiB
32Wrong answer2ms4324 KiB
33Wrong answer3ms4460 KiB
34Wrong answer3ms4532 KiB
35Wrong answer3ms4428 KiB
36Wrong answer2ms4428 KiB
37Wrong answer3ms4660 KiB
38Wrong answer2ms4636 KiB
39Wrong answer2ms4640 KiB
40Wrong answer2ms4640 KiB
41Wrong answer3ms4640 KiB
42Wrong answer2ms4744 KiB
43Wrong answer2ms4740 KiB