Submission #91018

# Submission time Handle Problem Language Result Execution time Memory
91018 2018-12-25T15:28:28 Z choikiwon parentrises (BOI18_parentrises) C++17
0 / 100
2 ms 720 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() == 0) {
            cout << "impossible\n";
            return;
        }
        int t = *R[1].rbegin();
        R[1].erase(t);
        rg--;
        B[1].insert(t);
        bg++;
    }
    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';
        }
    }

    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++) {
                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Incorrect 2 ms 500 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 548 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 548 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 548 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 720 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 720 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 720 KB Unexpected end of file - int32 expected