fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5.  
  6.  
  7. const int M = 1000000007;
  8. const int N = 3e5+9;
  9. const int INF = 2e9+1;
  10. const int MAXN = 100000;
  11. const int LINF = 2000000000000000001;
  12.  
  13. //_ ***************************** START Below *******************************
  14.  
  15.  
  16.  
  17. string a;
  18. string b;
  19.  
  20.  
  21.  
  22. //* Find a in-side b
  23. //* b == main string
  24.  
  25. bool consistency(int m, int n){
  26.  
  27. if(m>n) return false;
  28.  
  29. unordered_map<char, int> mp;
  30. for(int i=0; i<m; i++){
  31. mp[a[i]]++;
  32. }
  33. int size = mp.size();
  34. int s = 0, e = 0;
  35. while(e<n){
  36. if(mp.count(b[e])){
  37. mp[b[e]]--;
  38. if(mp[b[e]] == 0) size--;
  39. }
  40. if(e-s+1 < m){
  41. e++;
  42. }
  43. else{
  44. if(size==0) return true;
  45. if(mp.count(b[s])){
  46. mp[b[s]]++;
  47. if(mp[b[s]] == 1) size++;
  48. }
  49. s++;
  50. e++;
  51. }
  52. }
  53. return false;
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. bool practice(int m, int n){
  65.  
  66. return true;
  67. }
  68.  
  69.  
  70.  
  71.  
  72. void solve() {
  73.  
  74. cin >> a >> b;
  75. int m = a.size();
  76. int n = b.size();
  77.  
  78. cout << boolalpha << consistency(m, n) << endl;
  79.  
  80. // cout << boolalpha << consistency(m, n) << " -> " << practice(m, n) << endl;
  81.  
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88. int32_t main() {
  89. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  90.  
  91. int t = 1;
  92. cin >> t;
  93. while (t--) {
  94. solve();
  95. }
  96.  
  97. return 0;
  98. }
Success #stdin #stdout 0.01s 5276KB
stdin
2
hello ooolleoooleh
hello ooolleooolehl
stdout
false
true