SHARE
TWEET

Untitled

lalalalalalalaalalla Sep 24th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <iomanip>
  5. #include <queue>
  6. #include <cmath>
  7. #include <algorithm>
  8. #include <tuple>
  9. #include <iomanip>
  10. #include <stdio.h>
  11. #include <numeric>
  12. #include <map>
  13. #include <bitset>
  14. #include <set>
  15. #include <stack>
  16. #include <queue>
  17.  
  18. /*
  19. #pragma GCC optimize("Ofast,no-stack-protector")
  20. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
  21. #pragma GCC optimize("unroll-loops")
  22. #pragma GCC optimize("fast-math")
  23. #pragma GCC optimize("section-anchors")
  24. #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
  25. #pragma GCC optimize("vpt")
  26. #pragma GCC optimize("rename-registers")
  27. #pragma GCC optimize("move-loop-invariants")
  28. #pragma GCC optimize("unswitch-loops")
  29. #pragma GCC optimize("function-sections")
  30. #pragma GCC optimize("data-sections")
  31. #pragma GCC optimize("branch-target-load-optimize")
  32. #pragma GCC optimize("branch-target-load-optimize2")
  33. #pragma GCC optimize("btr-bb-exclusive")
  34. */
  35.  
  36. #define int long long
  37. #define ll long long
  38. #define ull unsigned long long
  39. #define all(a) a.begin(), a.end()
  40. #define pii pair<int, int>
  41. #define pb push_back
  42. #define ld long double
  43.  
  44.  
  45. using namespace std;
  46.  
  47. //const int INF = 1e13;
  48. //const int mod = 2600000069;
  49. //const int p = 179;
  50.  
  51. int n, m;
  52. set<string> ha;
  53. map<string, set<int>> ra;
  54.  
  55. signed main() {
  56.     ios_base::sync_with_stdio(0);
  57.     cin.tie(0);
  58.     cout.tie(0);
  59.     cin >> n >> m;
  60.     vector<string> a(n);
  61.     int k;
  62.     string s;
  63.     for (int i = 0; i < n; i++) {
  64.         cin >> a[i];
  65.         k = a[i].size();
  66.         if (k != 1) {
  67.             ha.insert(a[i]);
  68.             ra[a[i]].insert(i);
  69.             for (int j = 0; j < k; j++) {
  70.                 s = a[i];
  71.                 s.erase(s.begin() + j);
  72.                 ha.insert(s);
  73.                 ra[s].insert(i);
  74.             }
  75.         } else {
  76.             ha.insert("");
  77.             ra[""].insert(i);
  78.             ha.insert(a[i]);
  79.             ra[a[i]].insert(i);
  80.         }
  81.     }
  82.     string b;
  83.     int cnt;
  84.     set<int> ok;
  85.     map<string, int> ans;
  86.     map<string, bool> was;
  87.     map<string, string> kkk;
  88.     for (int i = 0; i < m; i++) {
  89.         cin >> b;
  90.         if (was[b]) {
  91.             cout << b << " " << ans[b] << " " << kkk[b] << "\n";
  92.             continue;
  93.         }
  94.         was[b] = 1;
  95.         ok.clear();
  96.         for (auto kk : ra[b]) {
  97.             ok.insert(kk);
  98.         }
  99.         k = b.size();
  100.         for (int j = 0; j < k; j++) {
  101.             s = b;
  102.             s.erase(s.begin() + j);
  103.             for (auto kk : ra[s]) {
  104.                 ok.insert(kk);
  105.             }
  106.         }
  107.         cnt = ok.size();
  108.         ans[b] = cnt;
  109.         if (cnt != 1) {
  110.             cout << b << " " << cnt << "\n";
  111.         } else {
  112.             cout << b << " 1 " << a[*ok.begin()] << "\n";
  113.             kkk[b] = a[*ok.begin()];
  114.         }
  115.     }
  116. }
  117. /*
  118. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top