結果

問題 No.464 PPAP
ユーザー chocoruskchocorusk
提出日時 2018-10-22 05:36:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,361 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 92,980 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 20:27:16
合計ジャッジ時間 1,955 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 45 ms
5,376 KB
testcase_11 AC 22 ms
5,376 KB
testcase_12 AC 33 ms
5,376 KB
testcase_13 AC 28 ms
5,376 KB
testcase_14 AC 29 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 27 ms
5,376 KB
testcase_24 AC 28 ms
5,376 KB
testcase_25 AC 28 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef unsigned long long ull;
ull powmod(ull a, ll k){
    if(a==0) return 0;
    ull ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
        }
        ap=ap*ap;
        k/=2;
    }
    return ans;
}
ull inv(ull a){
	return powmod(a, (1ll<<62)-1);
}
int main()
{
	string s;
	cin>>s;
	int n=s.size();
	ull h[5001], hr[5001];
	h[0]=(s[0]-'a');
	ull b=67;
	ull bp=b;
	for(int i=1; i<n; i++){
		h[i]=h[i-1]+(bp*(s[i]-'a'));
		bp*=b;
	}
	hr[n]=0;
	hr[n-1]=(s[n-1]-'a');
	bp=b;
	for(int i=n-2; i>=0; i--){
		hr[i]=hr[i+1]+(bp*(s[i]-'a'));
		bp*=b;
	}
	ull br=inv(b);
	ull brp[5000];
	brp[0]=1;
	for(int i=1; i<n; i++) brp[i]=brp[i-1]*br;
	ll ct1[5000];
	ct1[0]=0;
	for(int i=1; i<n; i++){
		ct1[i]=0;
		for(int j=0; j<i; j++){
			if(h[j]==(hr[0]-hr[j+1])*brp[n-1-j] && (h[i]-h[j])*brp[j+1]==(hr[j+1]-hr[i+1])*brp[n-1-i]) ct1[i]++;
		}
	}
	ll ans=0;
	for(int i=1; i<n; i++){
		for(int j=i+2; j<n; j++){
			if((h[n-1]-h[j-1])*brp[j]==hr[j]) ans+=ct1[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}
0