Submission #705016

# Submission time Handle Problem Language Result Execution time Memory
705016 2023-03-03T08:04:48 Z guagua0407 Superpozicija (COCI22_superpozicija) C++17
0 / 110
449 ms 448 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define all(x) x.begin(),x.end()

int trans(char a){
    return (a=='('?1:-1);
}

void solve(){
    int n;
    cin>>n;
    string str;
    cin>>str;
    vector<pair<int,int>> num(n);
    for(int i=0;i<n;i++){
        cin>>num[i].f>>num[i].s;
        num[i].f--;
        num[i].s--;
    }
    for(int i=0;i<(1<<n);i++){
        vector<int> ans;
        vector<pair<int,int>> cur;
        for(int j=0;j<n;j++){
            if(i&(1<<j)){
                ans.push_back(1);
                cur.push_back({num[j].s,trans(str[num[j].s])});
            }
            else{
                ans.push_back(0);
                cur.push_back({num[j].f,trans(str[num[j].f])});
            }
        }
        sort(all(cur));
        bool tf=true;
        int cnt=0;
        for(int i=0;i<n;i++){
            cnt+=cur[i].s;
            if(cnt<0) tf=false;
        }
        if(tf and cnt==0){
            for(int i=0;i<n;i++){
                cout<<ans[i]<<' ';
            }
            return;
        } 
    }
    cout<<-1;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
        cout<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 449 ms 448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 449 ms 448 KB Output isn't correct
2 Halted 0 ms 0 KB -