fork(1) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-6
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. using namespace std;
  28. // mylittledoge
  29.  
  30. int main() {
  31. cin.sync_with_stdio(0);
  32. cin.tie(0);
  33. int N;
  34. cin >> N;
  35. vector<string> V(N);
  36. for(int i =0; i < N; i++) cin >> V[i];
  37. sort(V.begin(),V.end());
  38. string S;
  39. cin >> S;
  40. int L =S.length();
  41. vector<int> ans(L+1,L+1);
  42. ans[0] =0;
  43. for(int i =0; i < L; i++) {
  44. ans[i+1] =min(ans[i+1],ans[i]+1);
  45. int t =0;
  46. for(int j =0; j < N; j++) if(V[j].length() >= i && V[j].substr(0,i) == S.substr(0,i)) {
  47. t++;
  48. if(S.length() >= V[j].length() && S.substr(0,V[j].length()) == V[j])
  49. ans[V[j].length()] =min(ans[V[j].length()],ans[i]+t);
  50. }
  51. }
  52.  
  53. cout << ans[L]+1 << "\n";
  54. return 0;}
  55.  
  56. // look at my code
  57. // my code is amazing
Runtime error #stdin #stdout #stderr 0s 3484KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc