-
Notifications
You must be signed in to change notification settings - Fork 0
/
L14-1.cpp
51 lines (40 loc) · 853 Bytes
/
L14-1.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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
#define PUB push_back
#define fi first
#define se second
int N, ans = 0;
string S, fin = "";
char trans[4][4] = {{'A', 'B', 'C', 'D'},
{'B', 'A', 'D', 'C'},
{'C', 'D', 'A', 'B'},
{'D', 'C', 'B', 'A'}};
string ubah(string &a, int thn){
string ret = a;
for(int i=0;i<N;i++){
int nxt = (i+thn) % N;
ret[i] = trans[a[i]-'A'][a[nxt]-'A'];
}
return ret;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> S;
N = S.length();
for(int i=0;i<N;i++) fin += "A";
for(int i=21;i>=0;i--){
string now = ubah(S, (1 << i));
if(now != fin){
if(i == 21){
cout << -1 << endl;
return 0;
}
ans += (1 << i);
S = now;
}
}
if(S == fin) cout << 0 << endl;
else cout << ans + 1 << endl;
}