From 8d5d8efebdd9d9d54ce005816d67edb44621d7bb Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 7 Nov 2022 07:43:04 +0800 Subject: [PATCH] P4421 [COCI2017-2018#1] Lozinke https://www.luogu.com.cn/record/93125374 --- Luogu/P4421/P4421.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Luogu/P4421/P4421.cpp diff --git a/Luogu/P4421/P4421.cpp b/Luogu/P4421/P4421.cpp new file mode 100644 index 00000000..fa1ed424 --- /dev/null +++ b/Luogu/P4421/P4421.cpp @@ -0,0 +1,45 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 20005; + +int n, 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++) { + std::unordered_map map2; + + cin >> s[i]; + + for (int j = 0; j < s[i].size(); j++) { + for (int k = j; k < s[i].size(); k++) { + std::string t = s[i].substr(j, k - j + 1); + + if (!map2[t]) { + map[t]++; + map2[t] = true; + } + } + } + } + + for (int i = 1; i <= n; i++) { + ans += map[s[i]] - 1; + } + + cout << ans << endl; + + return 0; +}