Iamtui1010

password.cpp

Jan 12th, 2022
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<vector>
  4. #include<unordered_map>
  5. #include<map>
  6.  
  7. #define long long long
  8. #define nln '\n'
  9.  
  10. using namespace std;
  11.  
  12. int main()
  13. {
  14.     cin.tie(0)->sync_with_stdio(0);
  15.     cout.tie(0)->sync_with_stdio(0);
  16.     //freopen("password.inp", "r", stdin);
  17.     long n;
  18.     cin >> n;
  19.     unordered_map<string, long> cnt1, cnt2;
  20.     // cnt1 la dem nguyen xau
  21.     // cnt2 la dem tung thanh phan cua xau 
  22.     long ans = 0;
  23.     while (n--){
  24.         string str;
  25.         cin >> str;
  26.         ans += cnt2[str];
  27.         map<string, bool> tic;
  28.         for (long i = 0; i < (long)str.size(); ++i)
  29.             for (long j = 0; j < (long)str.size()-i; ++j){
  30.                 if (tic[str.substr(j, i+1)])
  31.                     continue;
  32.                 ans += cnt1[str.substr(j, i+1)];
  33.                 ++cnt2[str.substr(j, i+1)];
  34.                 tic[str.substr(j, i+1)] = 1;}
  35.         ++cnt1[str];}  
  36.     cout << ans << nln;
  37.     return 0;
  38. }  
Advertisement
Add Comment
Please, Sign In to add comment