結果

問題 No.464 PPAP
ユーザー kotatsugamekotatsugame
提出日時 2020-03-05 08:41:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 833 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 72,256 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 02:05:20
合計ジャッジ時間 1,637 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 21 ms
6,940 KB
testcase_11 AC 11 ms
6,944 KB
testcase_12 AC 18 ms
6,944 KB
testcase_13 AC 11 ms
6,944 KB
testcase_14 AC 11 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 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,944 KB
testcase_23 AC 11 ms
6,940 KB
testcase_24 AC 11 ms
6,944 KB
testcase_25 AC 11 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   21 | main()
      | ^~~~

ソースコード

diff #

using namespace std;
#include<vector>
#include<string>
vector<int>Manachar(const string&s)
{
	vector<int>ret(s.size());
	int i=0,j=0;
	while(i<s.size())
	{
		while(i-j>=0&&i+j<s.size()&&s[i-j]==s[i+j])j++;
		ret[i]=j;
		int k=1;
		while(i-k>=0&&i+k<s.size()&&k+ret[i-k]<j)ret[i+k]=ret[i-k],k++;
		i+=k;j-=k;
	}
	return ret;
}
#include<iostream>
string s;
int cnt[5050];
main()
{
	cin>>s;
	string t="";
	t+=s[0];
	for(int i=1;i<s.size();i++)t+='$',t+=s[i];
	vector<int>M=Manachar(t);
	for(int i=0;i<s.size();i++)
	{
		int len=i+1;
		if(M[i]>=len)
		{
			for(int j=i+1;j<s.size();j++)
			{
				int len2=j-i;
				if(M[i*2+1+len2]>=len2)cnt[j]++;
			}
		}
	}
	long ans=0,cs=0;
	for(int i=1;i+2<s.size();i++)
	{
		for(int j=i+2;j<s.size();j++)
		{
			int len=s.size()-j;
			if(M[M.size()-len]>=len)ans+=cnt[i];
		}
	}
	cout<<ans<<endl;
}
0