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