Submission #480123

#TimeUsernameProblemLanguageResultExecution timeMemory
480123hidden1parentrises (BOI18_parentrises)C++14
50 / 100
164 ms7216 KiB
#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, red;
        int balance = 0;
        bool good = true;
        for(int i = 0; i < s.size(); i ++) {
            ans += '?';
        }
        for(int i = 0; i < s.size(); i ++) {
            auto it = s[i];
            if(it == '(') {
                blue.push_back(i);
                red.push_back(i);
            } else {
                if(blue.empty()) {
                    if(red.empty()) {
                        good = false;
                        break;
                    } else {
                        ans[red.back()] = 'G';
                        ans[i] = 'R';
                        red.pop_back();
                    }
                } else {
                    ans[blue.back()] = 'B';
                    ans[i] = 'B';                    
                    blue.pop_back();
                }
            }
        }
        vector<int> notUsed;
        for(int i = 0; i < s.size(); i ++) {
            auto it = s[i];
            if(ans[i] == '?') {
                notUsed.push_back(i);
            } else if(it == ')' && !notUsed.empty()) {
                if(ans[i] == 'R') {
                    ans[notUsed.back()] = 'B';
                    notUsed.pop_back();
                    ans[i] = 'G';
                } else if(ans[i] == 'B') {
                    ans[notUsed.back()] = 'R';
                    notUsed.pop_back();
                    ans[i] = 'G';                    
                }
            }
        }
        if(good && notUsed.empty()) {
            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 (stderr)

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:39:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for(int i = 0; i < s.size(); i ++) {
      |                        ~~^~~~~~~~~~
parentrises.cpp:62:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for(int i = 0; i < s.size(); i ++) {
      |                        ~~^~~~~~~~~~
parentrises.cpp:34:13: warning: unused variable 'balance' [-Wunused-variable]
   34 |         int balance = 0;
      |             ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...