結果
| 問題 |
No.464 PPAP
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2018-10-22 05:36:14 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 1,361 bytes |
| コンパイル時間 | 728 ms |
| コンパイル使用メモリ | 93,852 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-19 03:35:06 |
| 合計ジャッジ時間 | 1,982 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 22 |
ソースコード
#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;
}
chocorusk