0w1

ABC 043 D - アンバランス ( Trick Problem )

D: アンバランス / Unbalanced - AtCoder Beginner Contest 043 | AtCoder
A real nice trick problem.
Since it is only asks whether in some contiguous range one particular character appeared more than half of the length, we are to realize that if such range exists, the shortest form will either be "XX" or "X#X". If we consider "X#$X", or even longer random string sandwiched between the two Xs, we will find that it can totally be disregarded for it does not help attain our objective at all.

void solve(){
    string s; cin >> s;
    for( int i = 0; i + 1 < s.size(); ++i )
        if( s[ i ] == s[ i + 1 ] ){
            cout << i + 1 << " " << i + 2 << "\n";
            return;
        }
    for( int i = 0; i + 2 < s.size(); ++i )
        if( s[ i ] == s[ i + 2 ] ){
            cout << i + 1 << " " << i + 3 << "\n";
            return;
        }
    cout << -1 << " " << -1 << "\n";
}