Submission #98570

# Submission time Handle Problem Language Result Execution time Memory
98570 2019-02-24T13:11:10 Z tdwn parentrises (BOI18_parentrises) C++17
0 / 100
3 ms 384 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

string code;

void solve() {
    cin>>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()] = answ[i] = 'R';
                s2.push(s1.top());
                s1.pop();
            }
            else if(s2.size() > 0) {
                answ[s2.top()] = 'G';
                answ[i] = 'B';
                s2.pop();
            }
            else {
                cout<<"Impossible\n";
                return;
            }
        }
    }

    stack<int>t1, t2;
    for(int i=code.length()-1;i>=0;i--) {
        if(code[i] == ')') {
            t1.push(i);
        }
        else {
            if(answ[i] == 'R' || answ[i] == 'G') continue;
            else {
                if(t1.size() > 0) {
                    answ[i] = 'B';
                    answ[t1.top()] = 'G';
                    t1.pop();
                }
                else {
                    cout<<"impossible\n";
                    return;
                }
            }
        }
    }
    cout<<answ<<"\n";
    return;
}

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

    while(T--) {
        solve();
    }
    return 0;
}

Compilation message

parentrises.cpp: In function 'void solve()':
parentrises.cpp:14: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 3 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Incorrect 3 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Expected integer, but "Impossible" found
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Expected integer, but "Impossible" found
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Expected integer, but "Impossible" found