-
Notifications
You must be signed in to change notification settings - Fork 35
/
1108C - Nice Garland.cpp
196 lines (184 loc) · 4.62 KB
/
1108C - Nice Garland.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i,a,b) for(ll i=a;i<=b;++i)
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define clr(x) x.clear()
#define MOD 1000000007
#define itoc(c) ((char)(((int)'0')+c))
#define vl vector<ll>
#define SZ(x) (x).size()
#define all(p) p.begin(),p.end()
#define mid(s,e) (s+(e-s)/2)
#define sv() ll t,n; scanf("%lld",&t);n=t; while(t--)
#define tcase() ll t,n; cin>>t;n=t; while(t--)
#define iscn(num) scanf("%d",&num);
using namespace std;
typedef pair<ll,ll> Pair;
bool file=0,rt=1;
clock_t tStart ;
void FAST_IO();
////////////////////////
ll cnt[7];
int main()
{
FAST_IO();
////////////////////////
ll n;
cin>>n;
string s,rgb="RGB" , rbg="RBG" , brg="BRG" , bgr="BGR" , gbr="GBR" , grb="GRB";
cin>>s;
n=s.size();
for(int i=1,sz=s.size();i<=sz ; i++){
char ch=s[i-1];
ll j=0;
if(i%3==1){
j=0;
}
else if(i%3==2){
j=1;
}
else if(i%3==0){
j=2;
}
if(ch!=rgb[j])
cnt[1]++;
if(ch!=rbg[j])
cnt[2]++;
if(ch!=brg[j])
cnt[3]++;
if(ch!=bgr[j])
cnt[4]++;
if(ch!=gbr[j])
cnt[5]++;
if(ch!=grb[j])
cnt[6]++;
}
ll index=0,mini=INT_MAX;
for(int i=1; i<=6 ; i++){
// cout<<cnt[i]<<endl;
if(cnt[i]<mini){
index=i;
mini=cnt[i];
}
}
if(index==1)
s=rgb;
else if(index==2)
s=rbg;
else if(index==3)
s=brg;
else if(index==4)
s=bgr;
else if(index==5)
s=gbr;
else if(index==6)
s=grb;
cout<<mini<<endl;
for(int i=1; i<=n ; i++){
if(i%3==1)
cout<<s[0];
else if(i%3==2)
cout<<s[1];
else
cout<<s[2];
}
cout<<endl;
////////////////////////
if(rt && file){
printf("\nTime taken: %.6fs", (double)(clock() - tStart)/CLOCKS_PER_SEC);
}
return 0;
}
void FAST_IO()
{
ios_base::sync_with_stdio(0);
//cin.tie(NULL);
//cout.tie(NULL);
//cout.setf(ios::fixed);
//cout.precision(2);
if(rt && file){ tStart = clock(); }
if(file){
#ifndef _offline
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
}
//////////////////////////////////////////////////////////////////////////
/* or
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i,a,b) for(ll i=a;i<=b;++i)
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define clr(x) x.clear()
#define MOD 1000000007
#define itoc(c) ((char)(((int)'0')+c))
#define vl vector<ll>
#define SZ(x) (x).size()
#define all(p) p.begin(),p.end()
#define mid(s,e) (s+(e-s)/2)
#define sv() ll t,n; scanf("%lld",&t);n=t; while(t--)
#define tcase() ll t,n; cin>>t;n=t; while(t--)
#define iscn(num) scanf("%d",&num);
using namespace std;
typedef pair<ll,ll> Pair;
bool file=0,rt=1;
clock_t tStart ;
void FAST_IO();
////////////////////////
int main()
{
FAST_IO();
////////////////////////
ll n;
string s,final,x;
cin>>n>>s;
x="RGB";
sort(all(x));
ll temp=INT_MAX;
do{
ll t=0;
for(int i=0; i<n ; i++){
if(s[i]!=x[i%3])
t++;
}
if(t<temp){
final=x;
temp=t;
}
}while(next_permutation(all(x)));
cout<<temp<<endl;
for(int i=0; i<n ; i++){
cout<<final[i%3];
}
cout<<endl;
////////////////////////
if(rt && file){
printf("\nTime taken: %.6fs", (double)(clock() - tStart)/CLOCKS_PER_SEC);
}
return 0;
}
void FAST_IO()
{
ios_base::sync_with_stdio(0);
//cin.tie(NULL);
//cout.tie(NULL);
//cout.setf(ios::fixed);
//cout.precision(2);
if(rt && file){ tStart = clock(); }
if(file){
#ifndef _offline
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
}
*/