Advertisement
a53

cripto

a53
Mar 25th, 2020
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <fstream>
  2. #include <set>
  3. #define nmax 100005
  4. #define kmax 15
  5. #include <ctime>
  6. #define sigma 26
  7. #include <unordered_set>
  8. #include <string>
  9. #include <iostream>
  10.  
  11. using namespace std;
  12. ifstream f("cripto.in");
  13. ofstream g("cripto.out");
  14. string s[nmax], p[nmax], pcopy[nmax];
  15. int l[kmax];
  16. int n, m, k, q;
  17.  
  18. long long pnr[nmax];
  19. unordered_set <long long> my_set;
  20.  
  21. long long make_number(string p)
  22. {
  23. int ret = 0;
  24. for (int i = k - 1; i >= 0; i--)
  25. ret = ret * sigma + p[i] - 'a';
  26. return ret;
  27. }
  28. int main()
  29. {
  30.  
  31. clock_t t = clock();
  32.  
  33. int cntmax = -1, sol = 0;
  34. f >> n >> m >> k >> q;
  35. for (int i = 1; i <= n; i++) {
  36. f >> s[i];
  37. my_set.insert(make_number(s[i]));
  38. }
  39. for (int i = 1; i <= m; i++) {
  40. f >> p[i];
  41. pnr[i] = make_number(p[i]);
  42. }
  43. for (int i = 1; i <= q; i++) {
  44. int cnt = 0;
  45. long long hash_number = 0;
  46. for (int j = 0; j < k; j++)
  47. f >> l[j];
  48.  
  49. for (int j = k - 1; j >= 0; j--)
  50. hash_number = hash_number * sigma + l[j];
  51.  
  52. for (int j = 1; j <= m; j++)
  53. if (my_set.find(pnr[j] + hash_number) != my_set.end())
  54. cnt ++;
  55.  
  56. if (cnt > cntmax) {
  57. cntmax = cnt;
  58. sol = i;
  59. }
  60. }
  61. g << sol << ' ' << cntmax << '\n';
  62.  
  63. t = clock() - t;
  64. printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  65.  
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement