fork download
  1. #include<bits/stdc++.h>
  2.  
  3. #define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
  4. #define int long long
  5. #define inf (int)1e15
  6. #define pii pair<int,int>
  7. #define ff first
  8. #define ss second
  9.  
  10. using namespace std;
  11.  
  12. string s, t;
  13. unordered_map<char, int> req, freq;
  14.  
  15. bool isFind() {
  16. for (pii i : req)
  17. if (freq[i.ff] < i.ss) return false;
  18. return true;
  19. }
  20.  
  21. string stringWindow() {
  22.  
  23. int j = 0, st = 0, n = s.length();
  24. int ans = inf;
  25.  
  26. for (int i = 0; i < n; i++) {
  27. freq[s[i]]++;
  28.  
  29. while (isFind()) {
  30. int curLen = i - j + 1;
  31. if (curLen < ans)
  32. ans = curLen, st = j;
  33. freq[s[j]]--, j++;
  34. }
  35. }
  36.  
  37. if (ans == inf) return "No string";
  38. else return s.substr(st, ans);
  39. }
  40.  
  41. int32_t main() {
  42. fast
  43. int t_c = 1;
  44. // cin >> t_c;
  45. while (t_c--) {
  46. getline(cin, s), getline(cin, t);
  47. for (char c : t)
  48. req[c]++;
  49. cout << stringWindow() << endl;
  50. }
  51. }
Success #stdin #stdout 0s 4384KB
stdin
Standard input is empty
stdout
No string