結果

問題 No.464 PPAP
ユーザー imulanimulan
提出日時 2016-12-16 01:54:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 351 ms / 2,000 ms
コード長 1,140 bytes
コンパイル時間 2,021 ms
コンパイル使用メモリ 165,892 KB
実行使用メモリ 144,144 KB
最終ジャッジ日時 2023-08-20 08:40:23
合計ジャッジ時間 5,095 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,584 KB
testcase_01 AC 2 ms
5,476 KB
testcase_02 AC 2 ms
5,672 KB
testcase_03 AC 2 ms
5,632 KB
testcase_04 AC 4 ms
8,000 KB
testcase_05 AC 3 ms
7,892 KB
testcase_06 AC 3 ms
7,948 KB
testcase_07 AC 21 ms
45,160 KB
testcase_08 AC 20 ms
45,284 KB
testcase_09 AC 19 ms
45,204 KB
testcase_10 AC 351 ms
144,144 KB
testcase_11 AC 133 ms
111,532 KB
testcase_12 AC 281 ms
140,640 KB
testcase_13 AC 145 ms
140,416 KB
testcase_14 AC 237 ms
143,888 KB
testcase_15 AC 3 ms
5,592 KB
testcase_16 AC 2 ms
5,580 KB
testcase_17 AC 3 ms
7,652 KB
testcase_18 AC 2 ms
5,504 KB
testcase_19 AC 3 ms
7,936 KB
testcase_20 AC 3 ms
8,056 KB
testcase_21 AC 3 ms
7,724 KB
testcase_22 AC 3 ms
7,828 KB
testcase_23 AC 157 ms
132,500 KB
testcase_24 AC 196 ms
132,700 KB
testcase_25 AC 202 ms
134,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

// [i,j]が回文かどうか
int p[5000][5000]={};
// i文字目から始めるとき、j文字目までにある回文の累積和
int ct[5000][5000]={};

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

    int S=s.size();
    rep(i,S) p[i][i]=1;
    rep(i,S-1)if(s[i]==s[i+1]) p[i][i+1]=1;

    for(int b=2; b<S; ++b)
    {
        rep(i,S-b)
        {
            if(s[i]==s[i+b] && p[i+1][i+b-1]) p[i][i+b]=1;
        }
    }

    rep(i,S)
    {
        if(p[i][i]) ct[i][i]=1;
        for(int j=i+1; j<S; ++j)
        {
            ct[i][j] = ct[i][j-1];
            if(p[i][j]) ++ct[i][j];
        }
    }

    ll ans=0;
    rep(i,S-3)for(int j=i+3; j<S; ++j)if(p[0][i] && p[j][S-1])
    {
        // printf("(%d, %d): %d\n", i,j,ct[i+1][j-2]-ct[i+1][i]);
        ans += ct[i+1][j-2]-ct[i+1][i];
    }

    printf("%lld\n", ans);
    return 0;
}
0