Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- string s;
- cin >> s;
- int res =0 ;
- int n = (int) s.size();
- vector<int> v[26];
- for(int i = 0; i < n; i++) {
- v[s[i] - 'A'].push_back(i);
- }
- for(int i = 0; i < n; i++) {
- int c = s[i] - 'A';
- for(int k = (int) v[c].size() - 1; k >= 0; k--) {
- int p = v[c][k];
- if(p <= i) break;
- int sz = p - i + 1;
- if(sz % 4 == 0) {
- sz /= 4;
- int cnt = 1;
- bool ok = true;
- for(int j = i; j < i + sz; j++) {
- if(s[j] == s[i + 2 * sz - cnt] and s[j] == s[j + 2 * sz] and s[j] == s[i + 4 * sz - cnt]) {
- }
- else {
- ok = false;
- break;
- }
- cnt++;
- }
- if(ok) {
- res = max(res, 4 * sz);
- i = p;
- break;
- }
- }
- }
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement