#include <bits/stdc++.h>
#define N 305
using namespace std;
const int mod = 1e9 + 7;
int dp[N][N][N][2][2];
int ans[N];
void solve1(){
string s;
cin >> s;
int n = s.size();
vector<int> r,b;
int br = 0,bb = 0;
string ans = "";
for(int i = 0;i<n;i++){
ans += ".";
if(s[i] == '('){
if(br <= bb){
ans[i] = 'R';
br++;
r.push_back(i);
}
else{
ans[i] = 'B';
bb++;
b.push_back(i);
}
}
if(s[i] == ')'){
if(br + bb == 0){
if(r.empty() && b.empty()){
cout << "impossible" << endl;
return;
}
if(r.size() >= b.size()){
ans[r.back()] = 'G';
r.pop_back();
bb++;
}
else{
ans[b.back()] = 'G';
b.pop_back();
br++;
}
}
if(br >= bb){
ans[i] = 'R';
br--;
}
else{
ans[i] = 'B';
bb--;
}
}
}
for(int i = n-1;i>=0;i--){
if(s[i] == ')'){
if(ans[i] == 'B' && br){
ans[i] = 'G';
br--;
}
if(ans[i] == 'R' && bb){
ans[i] = 'G';
bb--;
}
}
}
if(br || bb){
cout << "impossible" << endl;
return;
}
cout << ans << endl;
}
void solve2(){
int n;
cin >> n;
cout << ans[n] << endl;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
/*
dp[0][0][0][0][0] = 1;
for(int i = 0;i<N-2;i++){
for(int j = 0;j<N-2;j++){
for(int c = 0;c<=j;c++){
for(int d = 0;d<2;d++){
for(int e = 0;e<2;e++){
for(int f = 0;f<2;f++){
for(int g = 0;g<2;g++){
if(d == f && e > g)continue;
int dx = (f == 0?g+1:0);
int dy = (f == 1?g+1:0);
dp[i+1][j+dx][c+dy][f][g] = (dp[i+1][j+dx][c+dy][f][g] + dp[i][j][c][d][e]) % mod;
}
}
if(j == c){
if(i == 4 && dp[i][j][c][d][e]){
cout << i << " " << j << " " << c << " " << d << " " << e << " "<< dp[i][j][c][d][e] << endl;
}
ans[i] = (ans[i] + dp[i][j][c][d][e])%mod;
}
}
}
//dp[i+1][j+1][c] = (dp[i+1][j+1][c] + dp[i][j][c]) % mod;
//dp[i+1][j+2][c] = (dp[i+1][j+2][c] + dp[i][j][c]) % mod;
//dp[i+1][j][c+1] = (dp[i+1][j][c+1] + dp[i][j][c]) % mod;
//dp[i+1][j][c+2] = (dp[i+1][j][c+2] + dp[i][j][c]) % mod;
}
}
}*/
int type;
cin >> type;
int t=1;
cin>>t;
while(t--){
if(type == 1)
solve1();
if(type ==2)
solve2();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |