fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. inline int power(int a, int b) {
  6. int x = 1;
  7. while (b) {
  8. if (b & 1) x *= a;
  9. a *= a;
  10. b >>= 1;
  11. }
  12. return x;
  13. }
  14.  
  15.  
  16. const int M = 1000000007;
  17. const int N = 3e5+9;
  18. const int INF = 2e9+1;
  19. const int LINF = 2000000000000000001;
  20.  
  21. //_ ***************************** START Below *******************************
  22.  
  23. // dddeeeeeeeeeeepp deep
  24.  
  25.  
  26. void consistency(string s, string t) {
  27. int n = s.size();
  28. int m = t.size();
  29.  
  30. vector<int> f(26, 0), g(26, 0);
  31. for(int i=0; i<n; i++){
  32. f[s[i]-'a']++;
  33. }
  34.  
  35. for(int i=0; i<m; i++){
  36. g[t[i]-'a']++;
  37. }
  38.  
  39. int ans = INF;
  40. for(int i=0; i<26; i++){
  41. if(g[i] == 0) continue;
  42.  
  43. //* if any s freq < t freq then t can't fit in s => return 0
  44. if(f[i] < g[i]){
  45. cout << 0 << endl;
  46. return;
  47. }
  48. f[i] = f[i]/g[i];
  49.  
  50. ans = min(ans, f[i]);
  51. }
  52.  
  53. cout << ans << endl;
  54.  
  55. }
  56.  
  57. void solve() {
  58.  
  59. string s, t;
  60. cin >> s >> t;
  61. consistency(s, t) ;
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69. int32_t main() {
  70. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  71.  
  72. int t = 1;
  73. while (t--) {
  74. solve();
  75. }
  76.  
  77. return 0;
  78. }
Success #stdin #stdout 0s 5316KB
stdin
dddeeeeeeeeeeepp deep
stdout
2