Submission #847156

# Submission time Handle Problem Language Result Execution time Memory
847156 2023-09-09T08:50:42 Z Pacybwoah Superpozicija (COCI22_superpozicija) C++17
10 / 110
24 ms 3500 KB
#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        vector<pair<int,int> > vec(n);
        for(int i=0;i<n;i++) cin>>vec[i].first>>vec[i].second,vec[i].first--,vec[i].second--;
        if(n&1){
            cout<<"-1\n";
            continue;
        }
        vector<int> ans(n),pos;
        for(int i=0;i<n;i++){
            if(s[vec[i].first]=='('){
                pos.push_back(vec[i].first);
                ans[i]=0;
            }
            else{
                pos.push_back(vec[i].second);
                ans[i]=1;
            }
        }
        sort(pos.begin(),pos.end());
        int now=0;
        bool flag=1;
        for(int i=0;i<n;i++){
            if(s[pos[i]]=='('){
                now++;
            }
            else now--;
            if(now<0){
                flag=0;
                break;
            }
        }
        if(flag&&now==0){
            for(auto x:ans) cout<<x<<" ";
            cout<<"\n";
        }
        else cout<<"-1\n";
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 14 ms 348 KB Output is correct
2 Correct 18 ms 1736 KB Output is correct
3 Correct 16 ms 1824 KB Output is correct
4 Correct 17 ms 2112 KB Output is correct
5 Correct 15 ms 2464 KB Output is correct
6 Correct 10 ms 2140 KB Output is correct
7 Correct 13 ms 2516 KB Output is correct
8 Correct 15 ms 2852 KB Output is correct
9 Correct 19 ms 3172 KB Output is correct
10 Correct 24 ms 3500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -