Problem p04026 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define FOR(i, b, e) for (ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for (ll i = (ll)(e - 1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x, c) for (const auto &x : (c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define PAIR pair<ll, ll>
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

using ll = long long;
constexpr int MOD = 1000000007;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

VL prime_decomposition(ll n) {
  ll i = 2;
  VL table{};
  while (i * i <= n) {
    while (n % i == 0) {
      n /= i;
      table.emplace_back(i);
    }
    ++i;
  }
  if (n > 1) {
    table.emplace_back(n);
    return table;
  }
}

int main() {
  string str;
  cin >> str;

  VVL v;
  v.reserve(str.size() + 1);

  VL tmp(26, 0);
  v.emplace_back(tmp);
  REPC(c, str) {
    int n = c - 'a';
    ++tmp[n];
    v.emplace_back(tmp);
  }

  REP(i, str.size()) {
    FOR(j, i + 1, str.size()) {
      ll len = j - i + 1;
      ll max = 0;
      REP(n, 26) { max = std::max(max, v[j + 1][n] - v[i][n]); }
      if (max > len / 2) {
        cout << i + 1 << " " << j + 1 << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define FOR(i, b, e) for (ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for (ll i = (ll)(e - 1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x, c) for (const auto &x : (c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define PAIR pair<ll, ll>
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

using ll = long long;
constexpr int MOD = 1000000007;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

VL prime_decomposition(ll n) {
  ll i = 2;
  VL table{};
  while (i * i <= n) {
    while (n % i == 0) {
      n /= i;
      table.emplace_back(i);
    }
    ++i;
  }
  if (n > 1) {
    table.emplace_back(n);
    return table;
  }
}

int main() {
  string str;
  cin >> str;

  ll s = str.size();
  REP(i, s) {
    if (i < s - 1 && str[i] == str[i + 1]) {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    } else if (i < s - 2 && str[i] == str[i + 2]) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}