답안 #572587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572587 2022-06-04T17:55:27 Z model_code Superpozicija (COCI22_superpozicija) C++17
110 / 110
78 ms 5436 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long llint;
typedef pair <int, int> pi;

const int MAXN = 100005;

int n, tc;
int lef[MAXN], rig[MAXN], sol[MAXN];
string s;
set <int> st;
set <pi> pq;
vector <int> tmp;
vector <pi> v;

bool makni (int pos) {
    auto it = st.lower_bound(pos);
    if (it == st.end()) return 0;
    st.erase(it);
    return 1;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> tc;
    for (int t = 0; t < tc; t++) {
        st.clear(); pq.clear(); tmp.clear(); v.clear();
        bool rip = 0;

        cin >> n >> s;
        s = "." + s;
        for (int i = 1; i <= n; i++) {
            cin >> lef[i] >> rig[i];
            if (s[lef[i]] == '(' && s[rig[i]] == '(') {
                tmp.push_back(lef[i]);
                sol[i] = 0;
            } else if (s[lef[i]] == ')' && s[rig[i]] == ')') {
                st.insert(rig[i]);
                sol[i] = 1;
            } else if (s[lef[i]] == '(' && s[rig[i]] == ')') {
                st.insert(rig[i]);
                v.push_back({lef[i], i});
                sol[i] = 1;
            } else {
                st.insert(lef[i]);
                v.push_back({lef[i], i});
                sol[i] = 0;
            }
        }
        for (auto pos : tmp) {
            if (!makni(pos)) {
                cout << -1 << '\n';
                rip = 1;
                break;
            }
        }
        if (rip) continue;

        sort(v.begin(), v.end());
        int p = -1;
        while (!st.empty()) {
            int lim = *st.begin();
            while (p + 1 < v.size() && v[p + 1].first <= lim) {
                p++;
                int ind = v[p].second;
                pq.insert({rig[ind], ind});
            }
            bool ok = 1;
            if (pq.empty()) {
                ok = 0;
            } else {
                int ind = pq.begin() -> second;
                pq.erase(pq.begin());
                sol[ind] = !sol[ind];
                if (!makni(lef[ind])) ok = 0;
                if (!makni(rig[ind])) ok = 0;
            }
            if (!ok) {
                cout << -1 << '\n';
                rip = 1;
                break;
            }
        }
        if (rip) continue;

        for (int i = 1; i <= n; i++) {
            cout << sol[i] << " ";
        }
        cout << '\n';
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:66:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |             while (p + 1 < v.size() && v[p + 1].first <= lim) {
      |                    ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 404 KB Output is correct
2 Correct 31 ms 344 KB Output is correct
3 Correct 31 ms 364 KB Output is correct
4 Correct 32 ms 472 KB Output is correct
5 Correct 34 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 340 KB Output is correct
2 Correct 35 ms 724 KB Output is correct
3 Correct 39 ms 1104 KB Output is correct
4 Correct 34 ms 1512 KB Output is correct
5 Correct 30 ms 1908 KB Output is correct
6 Correct 22 ms 2256 KB Output is correct
7 Correct 39 ms 2632 KB Output is correct
8 Correct 31 ms 3080 KB Output is correct
9 Correct 38 ms 3360 KB Output is correct
10 Correct 34 ms 3724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 36 ms 412 KB Output is correct
3 Correct 38 ms 904 KB Output is correct
4 Correct 33 ms 1480 KB Output is correct
5 Correct 35 ms 2004 KB Output is correct
6 Correct 38 ms 2576 KB Output is correct
7 Correct 21 ms 3012 KB Output is correct
8 Correct 43 ms 3656 KB Output is correct
9 Correct 35 ms 4108 KB Output is correct
10 Correct 51 ms 4812 KB Output is correct
11 Correct 51 ms 5268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 404 KB Output is correct
2 Correct 31 ms 344 KB Output is correct
3 Correct 31 ms 364 KB Output is correct
4 Correct 32 ms 472 KB Output is correct
5 Correct 34 ms 468 KB Output is correct
6 Correct 25 ms 340 KB Output is correct
7 Correct 35 ms 724 KB Output is correct
8 Correct 39 ms 1104 KB Output is correct
9 Correct 34 ms 1512 KB Output is correct
10 Correct 30 ms 1908 KB Output is correct
11 Correct 22 ms 2256 KB Output is correct
12 Correct 39 ms 2632 KB Output is correct
13 Correct 31 ms 3080 KB Output is correct
14 Correct 38 ms 3360 KB Output is correct
15 Correct 34 ms 3724 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 36 ms 412 KB Output is correct
18 Correct 38 ms 904 KB Output is correct
19 Correct 33 ms 1480 KB Output is correct
20 Correct 35 ms 2004 KB Output is correct
21 Correct 38 ms 2576 KB Output is correct
22 Correct 21 ms 3012 KB Output is correct
23 Correct 43 ms 3656 KB Output is correct
24 Correct 35 ms 4108 KB Output is correct
25 Correct 51 ms 4812 KB Output is correct
26 Correct 51 ms 5268 KB Output is correct
27 Correct 41 ms 516 KB Output is correct
28 Correct 62 ms 1020 KB Output is correct
29 Correct 63 ms 1480 KB Output is correct
30 Correct 56 ms 2144 KB Output is correct
31 Correct 71 ms 2592 KB Output is correct
32 Correct 33 ms 3036 KB Output is correct
33 Correct 56 ms 3600 KB Output is correct
34 Correct 74 ms 4244 KB Output is correct
35 Correct 78 ms 4776 KB Output is correct
36 Correct 77 ms 5436 KB Output is correct