답안 #98568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98568 2019-02-24T12:02:38 Z tdwn parentrises (BOI18_parentrises) C++17
0 / 100
3 ms 384 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

string code;
string answ;
string fin;

string solve(string code) {
    string answ = code;

    stack<int>s1, s2;
    for(int i=0;i<code.length();i++) {
        if(code[i] == '(') {
            s1.push(i);
        }
        else {
            if(s1.size() > 0) {
                answ[s1.top()] = 'B';
                answ[i] = 'B';
                s2.push(s1.top());
                s1.pop();
            }
            else if(s2.size() > 0){
                answ[s2.top()] = 'G';
                answ[i] = 'R';
                s2.pop();
            }
        }
    }
    return answ;
}

bool invalid(char a, char b) {
    return (a == '(' && b == a) || (a == ')' && b == a) || (a == 'R' && b == 'B') || (a == 'B' && b == 'R');
}

void solvea() {
    cin>>code;
    string f = solve(code);
    reverse(code.begin(), code.end());

    for(int i=0;i<code.length();i++) {
        if(code[i] == '(') code[i] = ')';
        else code[i] = '(';
    }

    string s = solve(code);
    reverse(s.begin(), s.end());
    // merge them

    string answ = f;
    for(int i=0;i<f.length();i++) {
        if(invalid(s[i], f[i])) {
            cout<<"Impossible\n";
            return;
        }
        else {
            if(s[i] == 'G' || f[i] == 'G') answ[i] = 'G';
            else if(s[i] == f[i]) answ[i] = s[i];
            else if((s[i] != '(' && s[i] != ')') && (f[i] =='(' || f[i] == ')')) answ[i] = s[i];
            else if((f[i] != '(' && f[i] != ')') && (s[i] =='(' || s[i] == ')')) answ[i] = f[i];
        }

        if(answ[i] == '(' || answ[i] == ')') {
            cout<<"Impossible\n";
            return;
        }

    }
    cout<<answ<<"\n";
}

void solveb() {
    cout<<"0\n";
}

int main() {
    int P, T;
    cin>>P;
    cin>>T;

    while(T--) {
        if(P == 1) solvea();
        else solveb();
    }
    return 0;
}

Compilation message

parentrises.cpp: In function 'std::__cxx11::string solve(std::__cxx11::string)':
parentrises.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<code.length();i++) {
                 ~^~~~~~~~~~~~~~
parentrises.cpp: In function 'void solvea()':
parentrises.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<code.length();i++) {
                 ~^~~~~~~~~~~~~~
parentrises.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<f.length();i++) {
                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Incorrect 3 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct