Submission #480102

# Submission time Handle Problem Language Result Execution time Memory
480102 2021-10-14T15:28:11 Z hidden1 parentrises (BOI18_parentrises) C++14
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define debug(...) cout << "Line: " << __LINE__ << endl; \
    printDebug(", "#__VA_ARGS__, __VA_ARGS__)
template <typename T>
void printDebug(const char* name, T&& arg1) { cout << (name + 2) << " = " << arg1 << endl; }
template <typename T, typename... T2>
void printDebug(const char* names, T&& arg1, T2&&... args) {
    const char* end = strchr(names + 1, ',');
    cout.write(names + 2, end - names - 2) << " = " << arg1 << endl;
    printDebug(end, args...);
}
 
const int MAX_L = 1e5 + 10;

string s;

void solve1() {
    int t;
    cin >> t;
    while(t --) {
        cin >> s;
        string ans = "";
        vector<int> blue;
        int balance = 0;
        bool good = true;
        for(int i = 0; i < s.size(); i ++) {
            auto it = s[i];
            if(it == '(') {
                balance ++;
                ans += 'B';
                blue.push_back(i);
            } else {
                if(balance == 0) {
                    if(blue.empty()) {
                        good = false;
                        break;
                    } else {
                        ans[blue.back()] = 'G';
                        ans += 'R';
                        blue.pop_back();
                    }           
                } else {
                    balance --;
                    ans += 'B';
                }
            }
        }
        if(!good) {
            cout << "impossible" << endl;
            continue;
        }
        
        vector<int> blueHelper = {};
        reverse(blue.begin(), blue.end());
        for(int i = 0; i < s.size() && balance; i ++ ) {
            if(!blue.empty() && blue.back() == i) {
                blueHelper.push_back(i);
                blue.pop_back();
            } else if(s[i] == ')' && ans[i] == 'R') {
                if(!blueHelper.empty()) {
                    balance --;
                    ans[i] = 'G';
                    blueHelper.pop_back();
                }
            } else if(s[i] == ')' && ans[i] == 'B') {
                if(!blueHelper.empty()) {
                    balance --;
                    ans[blueHelper.back()] = 'R';
                    ans[i] = 'G';
                    blueHelper.pop_back();
                }
            }
        }
        if(balance == 0) {
            cout << ans << endl;
        } else {
            cout << "impossible" << endl;            
        }
    }
}

signed main() {
    // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int t;
    cin >> t;
    if(t == 1) {
        solve1();
    }

    return 0;
}

Compilation message

parentrises.cpp: In function 'void solve1()':
parentrises.cpp:36:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int i = 0; i < s.size(); i ++) {
      |                        ~~^~~~~~~~~~
parentrises.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int i = 0; i < s.size() && balance; i ++ ) {
      |                        ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected