結果
| 問題 |
No.263 Common Palindromes Extra
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-14 20:01:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,580 bytes |
| コンパイル時間 | 494 ms |
| コンパイル使用メモリ | 61,692 KB |
| 実行使用メモリ | 126,112 KB |
| 最終ジャッジ日時 | 2024-07-08 07:16:37 |
| 合計ジャッジ時間 | 2,315 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 11 |
ソースコード
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
struct Node {
int cnt;
Node* child[26];
Node():cnt(0){
memset(child, 0, sizeof(child));
}
void add(int n, int cnt){
if(child[n] == NULL){
child[n] = new Node;
}
child[n]->cnt += cnt;
}
};
void myfree(Node* a){
if(a == NULL)return;
for(int i=0;i<26;i++)myfree(a->child[i]);
delete a;
}
ll count(Node* a, Node* b){
if(a == NULL || b == NULL){
return 0;
}
ll res = a->cnt * b->cnt;
for(int i=0;i<26;i++){
res += count(a->child[i], b->child[i]);
}
return res;
}
Node* builder(const vector<int>& S, bool odd){
const int N = S.size();
Node *root = new Node;
for(int i=0;i<N;){
int j = i;
while(j < N && S[j] == S[i])++j;
Node *r = root;
int l = odd ? 1 : 2;
int len = j - i;
for(;l<=len;l+=2){
r->add(S[i], len-l+1);
r = r->child[S[i]];
}
if(l == len){
int s = i - 1;
int t = j;
while(s >= 0 && t < N && S[s] == S[t]){
r->add(S[s], 1);
r = r->child[S[s]];
--s;
++t;
}
}
i = j;
}
return root;
}
vector<int> conv(const string &S){
vector<int> res(S.size());
for(int i=0;i<S.size();i++){
res[i] = S[i] - 'A';
}
return res;
}
int main(){
string S, T;
cin >> S >> T;
vector<int> vs = conv(S), vt = conv(T);
Node *ns, *nt;
ll res = 0;
ns = builder(vs, true);
nt = builder(vt, true);
res += count(ns, nt);
myfree(ns);
myfree(nt);
ns = builder(vs, false);
nt = builder(vt, false);
res += count(ns, nt);
myfree(ns);
myfree(nt);
cout << res << endl;
return 0;
}