답안 #91019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91019 2018-12-25T15:36:06 Z choikiwon parentrises (BOI18_parentrises) C++17
0 / 100
2 ms 648 KB
#include<bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int MN = 333;

string S, ans;
set<int> R[2], B[2], G[2];

void main2() {
    cin >> S;

    for(int i = 0; i < 2; i++) {
        R[i].clear();
        B[i].clear();
        G[i].clear();
    }
    int rg = 0;
    int bg = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == '(') {
            rg++;
            R[1].insert(i);
        }
        else {
            if(rg) {
                rg--;
                R[0].insert(i);
            }
            else if(bg) {
                bg--;
                B[0].insert(i);
            }
            else {
                B[0].insert(i);
                if(R[1].size()) {
                    int t = *R[1].begin();
                    R[1].erase(t);
                    G[1].insert(t);
                }
                else {
                    cout << "impossible\n";
                    return;
                }
            }
        }
    }
    while(rg) {
        if(R[1].size()) {
            int t = *R[1].rbegin();
            R[1].erase(t);
            rg--;
            B[1].insert(t);
            bg++;
        }
        else {
            cout << "impossible\n";
            return;
        }
    }
    while(bg) {
        if(R[0].size()) {
            int t = *R[0].rbegin();
            R[0].erase(t);
            G[0].insert(t);
            bg--;
        }
        else {
            cout << "impossible\n";
            return;
        }
    }

    ans.clear();
    ans.resize(S.size());
    for(int i = 0; i < 2; i++) {
        for(auto it = R[i].begin(); it != R[i].end(); it++) {
            ans[*it] = 'R';
        }
        for(auto it = B[i].begin(); it != B[i].end(); it++) {
            ans[*it] = 'B';
        }
        for(auto it = G[i].begin(); it != G[i].end(); it++) {
            ans[*it] = 'G';
        }
    }

    rg = bg = 0;
    for(int i = 0; i < ans.size(); i++) {
        if(S[i] == '(') {
            if(ans[i] != 'B') rg++;
            if(ans[i] != 'R') bg++;
        }
        else {
            if(ans[i] != 'B') rg--;
            if(ans[i] != 'R') bg--;
        }
        if(rg < 0 || bg < 0) {
            cout << "impossible\n";
            return;
        }
    }

    cout << ans << endl;
}

void main3() {

}

int P, TC;
int main() {
    std::ios::sync_with_stdio(false);

    cin >> P >> TC;
    if(P == 1) {
        while(TC--) main2();
    }
    if(P == 2) {
        while(TC--) main3();
    }
}

Compilation message

parentrises.cpp: In function 'void main2()':
parentrises.cpp:20:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < S.size(); i++) {
                    ~~^~~~~~~~~~
parentrises.cpp:89:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < ans.size(); i++) {
                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Incorrect 2 ms 568 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 648 KB Output is correct
2 Incorrect 2 ms 648 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 648 KB Output is correct
2 Incorrect 2 ms 648 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 648 KB Output is correct
2 Incorrect 2 ms 648 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 648 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 648 KB Unexpected end of file - int32 expected
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 648 KB Unexpected end of file - int32 expected