-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
79 lines (69 loc) · 1.62 KB
/
C.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll n,k, ans=0;
string s;
void solve(){
ll mn1 = 0, mn2 = 0;
char cur1 = 'A', cur2 = 'B';
string t1, t2;
for(ll i=0;i<n;i++){
t1.push_back(cur1);
t2.push_back(cur2);
swap(cur1, cur2);
}
for(ll i=0;i<n;i++){
if(t1[i]!=s[i])
mn1++;
if(t2[i]!=s[i])
mn2++;
}
if(mn1<mn2){
cout<<mn1<<endl;
cout<<t1<<endl;
} else {
cout<<mn2<<endl;
cout<<t2<<endl;
}
}
int main(){
fast;
cin>>n>>k;
cin>>s;
string alpha("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
if(k==2){
solve();
return 0;
} else {
for(ll i=1;i<n-1;i++){
if(s[i]==s[i-1] && s[i]==s[i+1]){
for(ll j=0;j<k;j++){
if(alpha[j]!=s[i]){
s[i] = alpha[j];
break;
}
}
ans++;
} else if(s[i]==s[i-1]){
for(ll j=0;j<k;j++){
if(alpha[j]!=s[i-1] && alpha[j]!=s[i+1]){
s[i] = alpha[j];
break;
}
}
ans++;
}
}
if(s[n-1]==s[n-2]){
for(ll j=0;j<k;j++){
if(alpha[j]!=s[n-2])
s[n-1] = alpha[j];
}
ans++;
}
cout<<ans<<endl;
cout<<s<<endl;
}
return 0;
}