fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. const int string_len = 20;
  7. const int Uniq_Count = 100000;
  8. const int AllString = 1000000;
  9.  
  10. const int MAX_L = (Uniq_Count+1)*(string_len+1);
  11. int Forest[MAX_L][97];
  12.  
  13. char TestInput[Uniq_Count][string_len+1];
  14.  
  15.  
  16. int main() {
  17. // your code goes here
  18.  
  19. for (int i=0; i < Uniq_Count; i++){
  20. for (int j=0;j<string_len;j++)
  21. TestInput[i][j] = rand()%96 + 32;
  22. }
  23.  
  24. int Position = 0;
  25. int ans = 0;
  26.  
  27. for (int i=0;i<AllString;i++){
  28. char *k = TestInput[rand()%Uniq_Count]; //get random string
  29. int cur = 0;
  30. for (;*k;k++){
  31. if (Forest[cur][ *k - 32 ] == 0)
  32. Forest[cur][ *k - 32 ] = ++Position;
  33. cur = Forest[cur][ *k - 32 ];
  34. }
  35. ans += !Forest[cur][96];
  36. Forest[cur][96] = 1;
  37. }
  38. cout << ans;
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 1.32s 813056KB
stdin
Standard input is empty
stdout
99997