結果

問題 No.464 PPAP
ユーザー cielciel
提出日時 2016-12-15 22:00:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 827 ms / 2,000 ms
コード長 891 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 52,920 KB
実行使用メモリ 27,236 KB
最終ジャッジ日時 2023-08-20 07:43:58
合計ジャッジ時間 2,535 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 36 ms
9,092 KB
testcase_08 AC 5 ms
9,048 KB
testcase_09 AC 4 ms
8,760 KB
testcase_10 AC 827 ms
27,236 KB
testcase_11 AC 17 ms
23,428 KB
testcase_12 AC 27 ms
27,136 KB
testcase_13 AC 10 ms
27,064 KB
testcase_14 AC 43 ms
27,096 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 11 ms
26,748 KB
testcase_24 AC 10 ms
26,624 KB
testcase_25 AC 10 ms
26,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

char s[5001];
bool flg[5000][5000];
bool palindrome(int i,int j){
#if 0
	for(;i<j;i++,j--)if(s[i]!=s[j])return false;
	return true;
#else
	return flg[i][j];
#endif
}

int main(){
	long long r=0;
	scanf("%s",s);
	int len=strlen(s);

	for(int i=0;i<len;i++){
		//odd
		for(int j=0;0<=i-j&&i+j<len;j++){
			if(s[i-j]!=s[i+j])break;
			flg[i-j][i+j]=true;
		}
		//even
		for(int j=0;0<=i-j&&i+j+1<len;j++){
			if(s[i-j]!=s[i+j+1])break;
			flg[i-j][i+j+1]=true;
		}
	}

	vector<int>head,tail;
	for(int i=0;i<len;i++)if(palindrome(0,i))head.push_back(i);
	for(int i=0;i<len;i++)if(palindrome(i,len-1))tail.push_back(i);
	for(auto &e:head){
		for(int i=e+1;i<len;i++)
			if(palindrome(e+1,i))
				r+=distance(lower_bound(tail.begin(),tail.end(),i+2),tail.end());
	}
	printf("%lld\n",r);
	return 0;
}
0