Submission #98572

# Submission time Handle Problem Language Result Execution time Memory
98572 2019-02-24T13:17:40 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;
 
void solvea() {
    cin>>code;
    answ = code;
    stack<int>p1, p2;
 
    for(int i=0;i<code.length();i++) {
        if(code[i] == '(') {
            p1.push(i);
        }
        else {
            if(p1.size() != 0) {
                answ[i] = 'B';
                p2.push(p1.top());
                answ[p1.top()] = 'B';
                p1.pop();
            }
            else if(p2.size() != 0) {
                answ[p2.top()] = 'G';
                answ[i] = 'R';
                p2.pop();
            }
            else {
                cout<<"impossible\n";
                return;
            }
        }
    }
 
 
    while(p1.size() > 0) p1.pop();
    while(p2.size() > 0) p2.pop();
 
    for(int i=code.length()-1;i>=0;i--) {
        if(code[i] == ')' && answ[i] == 'B') {
            p1.push(i);
        }
        else if(code[i] == '(' && answ[i] == '(') {
            if(p1.size() != 0) {
                answ[p1.top()] = 'G';
                answ[i] = 'R';
            }
            else {
                cout<<"impossible\n";
                return;
            }
        }
    }
 
    cout<<answ<<"\n";
    return;
}
 
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 'void solvea()':
parentrises.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<code.length();i++) {
                 ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 356 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 356 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 356 KB Output isn't correct