結果

問題 No.464 PPAP
ユーザー cielciel
提出日時 2016-12-16 00:06:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 649 ms / 2,000 ms
コード長 633 bytes
コンパイル時間 631 ms
コンパイル使用メモリ 53,760 KB
実行使用メモリ 27,428 KB
最終ジャッジ日時 2024-05-07 15:18:38
合計ジャッジ時間 2,030 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 21 ms
8,504 KB
testcase_08 AC 4 ms
8,548 KB
testcase_09 AC 3 ms
8,704 KB
testcase_10 AC 649 ms
27,412 KB
testcase_11 AC 16 ms
23,068 KB
testcase_12 AC 21 ms
27,332 KB
testcase_13 AC 7 ms
27,324 KB
testcase_14 AC 30 ms
27,428 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 7 ms
27,140 KB
testcase_24 AC 6 ms
27,272 KB
testcase_25 AC 6 ms
27,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

char s[5001];
bool f[5000][5000];
int main(){
	long long r=0;
	scanf("%s",s);
	int len=strlen(s);

	for(int i=0;i<len;i++)for(int k=0;k<2;k++){
		for(int j=0;0<=i-j&&i+j+k<len;j++){
			if(s[i-j]!=s[i+j+k])break;
			f[i-j][i+j+k]=true;
		}
	}

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