This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 105
using namespace std;
const int mod = 1e9 + 7;
int val[N];
int ans[N];
void solve1(){
string s;
cin >> s;
int n = s.size();
vector<int> r,rr,points;
string ans = "";
for(int i = 0;i<n;i++){
ans += ".";
if(s[i] == '('){
ans[i] = 'R';
r.push_back(i);
rr.push_back(i);
}
if(s[i] == ')'){
if(rr.empty()){
if(r.empty()){
cout << "impossible" << endl;
return;
}
ans[r.back()] = 'G';
ans[i] = 'B';
r.pop_back();
continue;
}
rr.pop_back();
points.push_back(i);
ans[i] = 'R';
}
}
if(points.size() < rr.size()){
cout << "impossible" << endl;
return;
}
for(int i = 0;i<rr.size();i++){
ans[rr[i]] = 'B';
ans[points[points.size() - rr.size() + i]] = 'G';
if(rr[i] > points[points.size() - rr.size() + i]){
cout << "impossible" << endl;
return;
}
}
cout << ans << endl;
}
void solve2(){
int n;
cin >> n;
cout << (ans[n])%mod << 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
/*
for(int i = 0;i*3<N;i++){
int a = i,b = 2*i;
vector<vector<int>> dp(N,vector<int>(N,0));
dp[0][0] = 1;
for(int i = 0;i<N;i++){
for(int j = 0;j<N;j++){
bool ok = 1;
if(2*(i+1) < j)
ok = 0;
if(i + 1 > a)
ok = 0;
if(ok){
dp[i+1][j] = (dp[i+1][j] + dp[i][j])%mod;
}
ok = 1;
if(2*i < j+1)
ok = 0;
if(j + 1 > b)
ok = 0;
if(ok){
dp[i][j+1] = (dp[i][j+1] + dp[i][j])%mod;
}
}
}
cout << dp[a][b] << endl;
val[3*i] = dp[a][b];
}
for(int a = 1;a<N;a++){
for(int b = 1;b<=2*a;b++){
int br = a - b;
vector<vector<int>> dp(a+1,vector<int>(b+1,0));
dp[0][1] = 1;
for(int i = 0;i<=a;i++){
for(int j = 1;j<=b;j++){
bool ok = 1;
if(j < br && i == j+1)
ok = 0;
if(2*(a-i) < (b - j))
ok = 0;
if(i + 1 > a)
ok = 0;
if(ok){
dp[i+1][j] = (dp[i+1][j] + dp[i][j])%mod;
}
ok = 1;
if(2*(a-i) < (b - j))
ok = 0;
if(j + 1 > b)
ok = 0;
if(ok){
dp[i][j+1] = (dp[i][j+1] + dp[i][j])%mod;
}
}
}
if(a + b == 7){
cout << a << " " << b << " " << dp[a][b] << endl;
}
for(int i = 0;i<1;i++){
if(i + a + b < N)
ans[i + a + b] = (ans[i+a+b] + (long long)val[i]*dp[a][b])%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
}
Compilation message (stderr)
parentrises.cpp: In function 'void solve1()':
parentrises.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i = 0;i<rr.size();i++){
| ~^~~~~~~~~~
# | 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... |