//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC target("bmi,bmi2,popcnt,lzcnt")
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <fstream>
#include <climits>
#include <queue>
#include <algorithm>
#include <stdint.h>
#include <stack>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <cstring> // Для memset
#define endl '\n'
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
typedef pair <ld, ld> pdd;
const ll DIM = 700007;
const ll MXMASK = (1 << 21);
const ll INF = 1e18;
const ll mod = 998244353;
const ld eps = 0.00000000001;
const ld gr = (sqrt(5) + 1) / 2;
const ll offset = 10000;
const ll Bits = 20;
const ll dx[4] = { 1, 0, -1, 0 };
const ll dy[4] = { 0, 1, 0, -1 };
FILE* stream;
ll P;
bool check(ll o, ll c, const string& s) {
string p;
for (int j = 0; j < s.length(); j++) p += "0";
ll x = 0;
for (int j = 0; j < s.length(); j++) {
if (x == o) break;
if (s[j] == '(') {
p[j] = 'G';
x++;
}
}
x = 0;
for (int j = s.length() - 1; j >= 0; j--) {
if (x == c) break;
if (s[j] == ')') {
p[j] = 'G';
x++;
}
}
ll v1 = 0, v2 = 0;
bool flag = true;
for (int j = 0; j < s.length(); j++) {
if (p[j] == 'G') {
if (s[j] == '(') { v1++; v2++; }
if (s[j] == ')') { v1--; v2--; }
}
else {
if (s[j] == '(') {
if (v1 < v2) {
v1++;
p[j] = 'B';
}
else {
v2++;
p[j] = 'R';
}
}
else {
if (v1 > v2) {
v1--;
p[j] = 'B';
}
else {
v2--;
p[j] = 'R';
}
}
}
if (v1 < 0 || v2 < 0) flag = false;
}
if (v1 == 0 && v2 == 0 && flag) {
cout << p << endl;
return true;
}
return false;
}
void solve1() {
string s;
cin >> s;
ll open = 0, close = 0;
ll val = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '(') {
val++;
open++;
}
else {
val--;
close++;
}
}
if (val >= 0) {
for (int i = val; i <= close; i++) {
ll o = i - val;
if (check(o, i, s)) {
return;
}
}
cout << "impossible" << endl;
}
else {
for (int i = val; i <= open; i++) {
ll c = i - val;
if (check(i, c, s)) {
return;
}
}
cout << "impossible" << endl;
}
}
void solve2() {
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen_s(&stream, "input.txt", "r", stdin);
//freopen_s(&stream, "output.txt", "w", stdout);
cin >> P;
ll T;
cin >> T;
while (T--) {
if (P == 1) solve1();
if (P == 2) solve2();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |