답안 #666820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
666820 2022-11-29T18:58:12 Z Hacv16 Superpozicija (COCI22_superpozicija) C++17
0 / 110
155 ms 388 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAX = 2e6 + 50;
const int INF = 0x3f3f3f3f;

int tc, n, a[MAX], b[MAX];
string s;

bool valid(string& t){
    int aux = 0;

    for(int i = 0; i < t.size(); i++){
        if(t[i] == ')'){
            if(aux == 0) return false;
            else aux--;

        }else{
            aux++;
        }
    }

    if(aux) return false;
    return true;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> tc;

    while(tc--){
        cin >> n >> s;

        for(int i = 0; i < n; i++)
            cin >> a[i] >> b[i];

        for(int i = 0; i < n; i++) a[i]--, b[i]--;

        int ans = -1;

        for(int mask = 0; mask < (1 << n); mask++){
            string cur = "";

            for(int i = 0; i < n; i++){
                if(mask & (1 << i)) cur += s[a[i]];
                else cur += s[b[i]];
            }

            if(valid(cur)){
                ans = mask; break;
            }
        }

        if(ans == -1){
            cout << -1 << '\n';

        }else{
            for(int i = 0; i < n; i++)
                cout << (ans & (1 << i) ? 0 : 1) << ' ';
            cout << '\n';
        }
    }

    return 0;
}

Compilation message

Main.cpp: In function 'bool valid(std::string&)':
Main.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i = 0; i < t.size(); i++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 155 ms 388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 155 ms 388 KB Output isn't correct
2 Halted 0 ms 0 KB -