0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

P3449 [POI2006]PAL-Palindromes

https://www.luogu.com.cn/record/84232432
This commit is contained in:
Baoshuo Ren 2022-08-18 10:08:18 +08:00
parent ba8cf8cd9d
commit 6654bdef09
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

46
Luogu/P3449/P3449.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <iostream>
#include <string>
#include <unordered_map>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e6 + 5;
int n;
long long ans;
std::string s[N];
std::unordered_map<std::string, int> map;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1, _; i <= n; i++) {
cin >> _ >> s[i];
map[s[i]]++;
}
for (int i = 1; i <= n; i++) {
std::string str, str1(s[i]);
str.reserve(s[i].size());
str1.reserve(s[i].size() << 1);
for (char c : s[i]) {
str.push_back(c);
str1.push_back(c);
if (map.count(str) && str1 == str + s[i]) {
ans += static_cast<long long>(map[str]) * 2;
}
}
}
cout << ans - n << endl;
return 0;
}