Cod sursa(job #2366748)

Utilizator nicolaefilatNicolae Filat nicolaefilat Data 4 martie 2019 21:58:23
Problema PScPld Scor 0
Compilator cpp-64 Status done
Runda simulare04032019 Marime 0.81 kb
#include <iostream>
#include <fstream>

const int MAXN = 10000 + 5;

using namespace std;

ifstream in("pscpld.in");
ofstream out("pscpld.out");

string s;
int n;
bool dp[MAXN][MAXN];

int main()
{

    in.tie(NULL);
    out.tie(NULL);
    ios::sync_with_stdio(false);
    in>>s;
    int n = s.size() - 1;
    for(int i = 0; i <= n; ++i)
        dp[i][i] = true;
    for(int j = 0; j <= n; ++j){
        for(int i = 0; i <= j - 1; ++i){
            if(s[i] == s[j]){
                if(i == j - 1)
                    dp[i][j] = true;
                else
                    dp[i][j] = dp[i + 1][j - 1];
            }
        }
    }
    long long ans = 0;
    for(int i = 0; i <= n; ++i)
        for(int j = 0; j <= n; ++j)
            ans += dp[i][j];
    out<<ans;
    return 0;
}