結果
| 問題 |
No.263 Common Palindromes Extra
|
| コンテスト | |
| ユーザー |
sigma425
|
| 提出日時 | 2017-09-15 04:38:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,781 bytes |
| コンパイル時間 | 2,440 ms |
| コンパイル使用メモリ | 180,832 KB |
| 実行使用メモリ | 206,796 KB |
| 最終ジャッジ日時 | 2024-11-07 21:42:35 |
| 合計ジャッジ時間 | 6,567 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 MLE * 1 -- * 4 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef unsigned long long ll;
ll B=1e9+7;
int S[1000000];
ll hs[1000001];
map<ll,ll> has; //has->num
map<ll,ll> D,E;
map<ll,ll> nxt;
map<ll,vector<ll> > prv;
set<ll> doll; //$..$
void Manacher(string s){
int i=0,j=0;
while(i<s.size()){
while(i-j>=0&&i+j<s.size()&&s[i-j]==s[i+j]) ++j;
S[i]=j;
int k=1;
while(i-k>=0&&i+k<s.size()&&k+S[i-k]<j) S[i+k]=S[i-k],++k;
i+=k,j-=k;
}
}
ll ex(ll x,ll p){
ll a=1;
while(p){
if(p%2) a*=x;
x*=x;
p/=2;
}
return a;
}
ll H(int x,int y){ //[x,y)
return hs[y]-hs[x]*ex(B,y-x);
}
void dfs(ll h){
for(ll x:prv[h]){
dfs(x);
has[h]+=has[x];
}
}
void solve(){
string s,s_;
cin>>s_;
int N=s_.size();
s=s_[0];
rep1(i,N-1) s+="$",s+=s_[i];
N=s.size();
Manacher(s);
rep(i,N) hs[i+1]=hs[i]*B+s[i];
rep(i,N){
int x=S[i];
ll h=H(i-x+1,i+x);
bool fst=1;
while(!has.count(h)){
if(fst) has[h]++,fst=0;
has[h]; //access
if(s[i-x+1]=='$') doll.insert(h);
x--;
if(x==0) break;
ll nh=H(i-x+1,i+x);
nxt[h]=nh;
prv[nh].pb(h);
h=nh;
}
if(fst) has[h]++;
}
for(auto p:has){
ll h=p.fs;
if(!nxt.count(h)) dfs(h);
}
}
int main(){
solve();
D=has;
rep(i,1000000) S[i]=0;
rep(i,1000001) hs[i]=0;
has.clear();
nxt.clear();
prv.clear();
solve();
E=has;
ll ans=0;
/* for(auto p:E){
ll h=p.fs;
show(h);
show(E[h]);
}*/
for(auto p:D){
ll h=p.fs;
if(doll.count(h)) continue;
if(E.count(h)){
ans+=D[h]*E[h];
}
}
cout<<ans<<endl;
}
sigma425