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.  
  24.  
  25. void consistency(string s, string t) {
  26. int n = s.size();
  27. int m = t.size();
  28.  
  29. vector<int> f(26, 0), g(26, 0);
  30. for(int i=0; i<n; i++){
  31. f[s[i]-'a']++;
  32. }
  33.  
  34. for(int i=0; i<m; i++){
  35. g[t[i]-'a']++;
  36. }
  37.  
  38. int ans = INF;
  39. for(int i=0; i<26; i++){
  40. if(g[i] == 0) continue;
  41.  
  42. //* if any s freq < t freq then t can't fit in s => return 0
  43. if(f[i] < g[i]){
  44. cout << 0 << endl;
  45. return;
  46. }
  47. f[i] = f[i]/g[i];
  48.  
  49. ans = min(ans, f[i]);
  50. }
  51.  
  52. cout << ans << endl;
  53.  
  54. }
  55.  
  56. void solve() {
  57.  
  58. string s, t;
  59. cin >> s >> t;
  60. consistency(s, t) ;
  61.  
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. int32_t main() {
  69. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  70.  
  71. int t = 1;
  72. while (t--) {
  73. solve();
  74. }
  75.  
  76. return 0;
  77. }
Success #stdin #stdout 0s 5320KB
stdin
dddeeeeeeeeeeepp deep
stdout
2