답안 #810571

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
810571 2023-08-06T11:24:29 Z bonk Superpozicija (COCI22_superpozicija) C++14
10 / 110
382 ms 3024 KB
#include <bits/stdc++.h>

using namespace std;

int n;
string s;
vector<pair<int, int>>v;

bool valid(string s){
    int sum = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '(') sum++;
        else{
            sum--;
            if(sum < 0) return false;
        }
    }

    return (sum == 0);
}

void st1(){
    for(int i = 0; i < n; i++){
        cin >> v[i].first >> v[i].second;
        v[i].first--;
        v[i].second--;
    }

    int all = (1<<n);
    bool ok = false;
    for(int mask = 0; mask < all; mask++){
        if(ok) break;
        string cur = "";
        vector<int>tmp;
        for(int j = 0; j < n; j++){
            if((mask>>j)&1){
                tmp.push_back(v[j].second);
            } else{
                tmp.push_back(v[j].first);
            }
        }
        
        sort(tmp.begin(), tmp.end());
        for(auto &x: tmp) cur += s[x];

        if(valid(cur)){
            ok = true;
            for(int j = 0; j < n; j++){
                cout << ((mask>>j)&1) << " ";
            }
            cout << '\n';
        }
    }

    if(!ok) cout << -1 << '\n';
    return;
}

void solve(){
    cin >> n;
    cin >> s;
    v.resize(n);
    if(n <= 10){
        st1();
        return;
    }

    string cur = "";
    vector<int>tmp;

    for(int i = 0; i < n; i++){
        cin >> v[i].first >> v[i].second;
        v[i].first--; v[i].second--;
        if(s[v[i].first] == '(') tmp.push_back(v[i].first);
        else tmp.push_back(v[i].second);
    }

    sort(tmp.begin(), tmp.end());
    for(auto &x: tmp) cur += s[x];

    if(valid(cur)){
        for(int i = 0; i < n; i++){
            if(s[v[i].first] == '(') cout << 0 << ' ';
            else cout << 1 << ' ';
        }
        cout << '\n';
    } else{
        cout << -1 << '\n';
    }
    
    return;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc; cin >> tc;
    while(tc--){
        solve();
    }

    return 0;
}

Compilation message

Main.cpp: In function 'bool valid(std::string)':
Main.cpp:11:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i = 0; i < s.length(); i++){
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 382 ms 1068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1108 KB Output is correct
2 Correct 20 ms 1664 KB Output is correct
3 Correct 16 ms 1776 KB Output is correct
4 Correct 20 ms 2080 KB Output is correct
5 Correct 16 ms 2264 KB Output is correct
6 Correct 10 ms 1928 KB Output is correct
7 Correct 12 ms 2164 KB Output is correct
8 Correct 18 ms 2652 KB Output is correct
9 Correct 21 ms 2804 KB Output is correct
10 Correct 19 ms 3024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 382 ms 1068 KB Output isn't correct
2 Halted 0 ms 0 KB -