Cod sursa(job #2864754)

Utilizator cezar.balutaCezar Baluta cezar.baluta Data 8 martie 2022 10:45:31
Problema PScPld Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.25 kb
/*
                         __
                   _.--""  |
    .----.     _.-'   |/\| |.--.
    |    |__.-'   _________|  |_)  _______________
    |  .-""-.""""" ___,    `----'"))   __   .-""-.""""--._
    '-' ,--. `    |Cezar| .---.       |:.| ' ,--. `      _`.
     ( (    ) ) __|  7  |__\\|// _..-- \/ ( (    ) )--._".-.
      . `--' ;\__________________..--------. `--' ;--------'
       `-..-'                               `-..-'
*/
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;

const int N = 1e6 + 5;

char s[N];

int main() {
    ifstream in("pscpld.in");
    ofstream out("pscpld.out");
    in>>s;
    int cnt = 0;
    int  l =strlen(s);
    bool ok = true;
    for(int i=0;i<l;i++){
        int st=i,dr=i;
        if(s[i] == s[i+1])
            cnt++;
        ok = true;
        while(ok) {
            ok = false;
            if (st - 1 >= 0 && dr + 1 < l && s[st - 1] == s[dr + 1]) {
                cnt++;
                ok = true;
            }
            if (st - 1 >= 0 && dr + 2 < l && s[st - 1] == s[dr + 2] && s[st] == s[dr + 1]) {
                cnt++;
                ok = true;
            }
            if (ok) {
                st--;
                dr++;
            }
        }
    }
    out<<cnt + l;
    return 0;
}