답안 #1062344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062344 2024-08-17T03:37:18 Z bachhoangxuan Superpozicija (COCI22_superpozicija) C++17
110 / 110
21 ms 5076 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
int n,d[maxn],nxt[maxn],f[maxn],val[maxn];
char c[maxn];

void solve(){
    cin >> n;
    for(int i=1;i<=2*n;i++){
        cin >> c[i];
        nxt[i]=val[i]=f[i]=0;
    }
    for(int i=1;i<=n;i++){
        int a,b;cin >> a >> b;
        if(c[a]==c[b]){
            if(c[a]=='(') d[i]=0,val[a]++;
            else d[i]=1,val[b]--;
        }
        else{
            nxt[a]=b,f[a]=i;
            if(c[a]=='(') d[i]=1,val[b]--;
            else d[i]=0,val[a]--;
        }
    }
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    int cnt=0;
    for(int i=1;i<=2*n;i++){
        if(f[i]) pq.push({nxt[i],f[i]});
        cnt+=val[i];
        if(cnt<0){
            if(pq.empty()) break;
            auto [x,id]=pq.top();pq.pop();
            d[id]^=1;
            if(x<=i) cnt+=2;
            else cnt+=1,val[x]++;
        }
    }
    if(cnt) cout << -1 << '\n';
    else{
        for(int i=1;i<=n;i++) cout << d[i] << ' ';
        cout << '\n';
    }
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test;cin >> test;
    while(test--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2652 KB Output is correct
2 Correct 13 ms 3160 KB Output is correct
3 Correct 16 ms 3416 KB Output is correct
4 Correct 18 ms 3164 KB Output is correct
5 Correct 16 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2648 KB Output is correct
2 Correct 12 ms 2584 KB Output is correct
3 Correct 11 ms 2392 KB Output is correct
4 Correct 11 ms 2908 KB Output is correct
5 Correct 11 ms 2648 KB Output is correct
6 Correct 7 ms 2800 KB Output is correct
7 Correct 8 ms 2648 KB Output is correct
8 Correct 10 ms 2908 KB Output is correct
9 Correct 11 ms 2908 KB Output is correct
10 Correct 12 ms 3268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 14 ms 3328 KB Output is correct
3 Correct 15 ms 3676 KB Output is correct
4 Correct 14 ms 3676 KB Output is correct
5 Correct 16 ms 3928 KB Output is correct
6 Correct 20 ms 4108 KB Output is correct
7 Correct 7 ms 3408 KB Output is correct
8 Correct 13 ms 3928 KB Output is correct
9 Correct 12 ms 4184 KB Output is correct
10 Correct 17 ms 4576 KB Output is correct
11 Correct 21 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2652 KB Output is correct
2 Correct 13 ms 3160 KB Output is correct
3 Correct 16 ms 3416 KB Output is correct
4 Correct 18 ms 3164 KB Output is correct
5 Correct 16 ms 3420 KB Output is correct
6 Correct 15 ms 2648 KB Output is correct
7 Correct 12 ms 2584 KB Output is correct
8 Correct 11 ms 2392 KB Output is correct
9 Correct 11 ms 2908 KB Output is correct
10 Correct 11 ms 2648 KB Output is correct
11 Correct 7 ms 2800 KB Output is correct
12 Correct 8 ms 2648 KB Output is correct
13 Correct 10 ms 2908 KB Output is correct
14 Correct 11 ms 2908 KB Output is correct
15 Correct 12 ms 3268 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 14 ms 3328 KB Output is correct
18 Correct 15 ms 3676 KB Output is correct
19 Correct 14 ms 3676 KB Output is correct
20 Correct 16 ms 3928 KB Output is correct
21 Correct 20 ms 4108 KB Output is correct
22 Correct 7 ms 3408 KB Output is correct
23 Correct 13 ms 3928 KB Output is correct
24 Correct 12 ms 4184 KB Output is correct
25 Correct 17 ms 4576 KB Output is correct
26 Correct 21 ms 4952 KB Output is correct
27 Correct 19 ms 3416 KB Output is correct
28 Correct 19 ms 3860 KB Output is correct
29 Correct 18 ms 3804 KB Output is correct
30 Correct 20 ms 4284 KB Output is correct
31 Correct 19 ms 4084 KB Output is correct
32 Correct 12 ms 3808 KB Output is correct
33 Correct 14 ms 4064 KB Output is correct
34 Correct 17 ms 4320 KB Output is correct
35 Correct 19 ms 4572 KB Output is correct
36 Correct 21 ms 5076 KB Output is correct