結果
| 問題 |
No.263 Common Palindromes Extra
|
| コンテスト | |
| ユーザー |
HIR180
|
| 提出日時 | 2021-10-12 18:48:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 5,084 bytes |
| コンパイル時間 | 3,731 ms |
| コンパイル使用メモリ | 191,776 KB |
| 最終ジャッジ日時 | 2025-01-25 00:14:55 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 MLE * 2 |
ソースコード
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <iomanip>
#include <chrono>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#define int long long
#define L __int128
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
template<class t> using vc=vector<t>;
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
return os<<"{"<<p.fi<<","<<p.sc<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
template<class T>
void g(T &a){
cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
a+=b;
if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
ll res=1;
while(n>0){
if(n&1) res=res*x%mod;
x=x*x%mod;
n>>=1;
}
return res;
}
#define _sz 1
ll F[_sz],R[_sz];
void make(){
F[0] = 1;
for(int i=1;i<_sz;i++) F[i] = F[i-1]*i%mod;
R[_sz-1] = modpow(F[_sz-1], mod-2);
for(int i=_sz-2;i>=0;i--) R[i] = R[i+1] * (i+1) % mod;
}
ll C(int a,int b){
if(b < 0 || a < b) return 0;
return F[a]*R[b]%mod*R[a-b]%mod;
}
//ID * 30 + char -> next_ID
unordered_map<int, int>hsh[500005];
int nxt = 1;
int num[2][1000005];
constexpr int maxn = 1000005, alpha = 26;
struct eertree{
int len[maxn], link[maxn], to[maxn][alpha], cnt[maxn], id[maxn];
int slink[maxn], diff[maxn];
int sz, last, n;
char ch[maxn];
vc<int>edge[maxn];
//0...「0」の頂点
//1...「-1」の頂点
//len... その頂点番号の文字列の長さ
//link... suffix linkを1つたどった先
//to... 今の状態からこの文字を足すとどこに行きますか?
//diff...len[x]-len[link[x]]
//slink... diffが切り替わるところ (diffが同じところをぶっ飛ばすとO(log N)になる)
void init(){
n = 0;
last = 0;
ch[n++] = -1;
link[0] = 1;
edge[1].pb(0);
len[1] = -1;
sz = 2;
}
//len[1] = -1なので少なくとも「-1」では止まる
//なかなかやる
int get_link(int v){
while(ch[n-len[v]-2] != ch[n-1]) v = link[v];
return v;
}
//基本的にインクリメンタルな仕様が想定されていそう
void add_letter(char c){
ch[n++] = c -= 'A';
//まずこの末端がもつ最長の回文を見つけようね!
last = get_link(last);
int cur_id;
if(hsh[len[last]+1].find(id[last] * 30 + c) == hsh[len[last]+1].end()){
hsh[len[last]+1][id[last] * 30 + c] = nxt ++;
}
cur_id = hsh[len[last]+1][id[last] * 30 + c];
//この遷移は初めてか?力抜けよ
if(!to[last][c]){
//ここら辺はうんという感じで
len[sz] = len[last] + 2;
link[sz] = to[get_link(link[last])][c];
edge[link[sz]].pb(sz);
diff[sz] = len[sz] - len[link[sz]];
//slinkを踏むと1系列ぶっ飛ばせる
//つよいね~
if(diff[sz] == diff[link[sz]]){
slink[sz] = slink[link[sz]];
}
else{
slink[sz] = link[sz];
}
//ここもまあうん
to[last][c] = sz++;
}
last = to[last][c];
cnt[last] ++;
id[last] = cur_id;
}
void up(int wh, int v){
for(auto i:edge[v]){
up(wh, i);
cnt[v] += cnt[i];
}
num[wh][id[v]] = cnt[v];
}
}k, f;
void solve(){
string a, b; cin >> a >> b;
k.init();
f.init();
for(auto c:a) k.add_letter(c);
for(auto c:b) f.add_letter(c);
k.up(0, 1);
f.up(1, 1);
ll ans = 0;
repn(i, 1000004) ans += 1LL * num[0][i] * num[1][i];
o(ans);
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
int t; t = 1; //cin >> t;
while(t--) solve();
}
HIR180