Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- #include<vector>
- #include<unordered_map>
- #include<map>
- #define long long long
- #define nln '\n'
- using namespace std;
- int main()
- {
- cin.tie(0)->sync_with_stdio(0);
- cout.tie(0)->sync_with_stdio(0);
- //freopen("password.inp", "r", stdin);
- long n;
- cin >> n;
- unordered_map<string, long> cnt1, cnt2;
- // cnt1 la dem nguyen xau
- // cnt2 la dem tung thanh phan cua xau
- long ans = 0;
- while (n--){
- string str;
- cin >> str;
- ans += cnt2[str];
- map<string, bool> tic;
- for (long i = 0; i < (long)str.size(); ++i)
- for (long j = 0; j < (long)str.size()-i; ++j){
- if (tic[str.substr(j, i+1)])
- continue;
- ans += cnt1[str.substr(j, i+1)];
- ++cnt2[str.substr(j, i+1)];
- tic[str.substr(j, i+1)] = 1;}
- ++cnt1[str];}
- cout << ans << nln;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment