From 6654bdef0996f15b078fd6e38c9fffff514ecba3 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 18 Aug 2022 10:08:18 +0800 Subject: [PATCH] P3449 [POI2006]PAL-Palindromes https://www.luogu.com.cn/record/84232432 --- Luogu/P3449/P3449.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Luogu/P3449/P3449.cpp diff --git a/Luogu/P3449/P3449.cpp b/Luogu/P3449/P3449.cpp new file mode 100644 index 00000000..72419de8 --- /dev/null +++ b/Luogu/P3449/P3449.cpp @@ -0,0 +1,46 @@ +#include +#include +#include + +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 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(map[str]) * 2; + } + } + } + + cout << ans - n << endl; + + return 0; +}