Advertisement
skimono

Untitled

Mar 5th, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. int k;
  7. const int sz = 15000;
  8. vector<int> p;
  9.  
  10. void conv(string& s) {
  11. string t;
  12. t.resize(s.size());
  13. for (int i = 0; i < s.size(); i++) {
  14. if (s[i] == 35 || s[i] == 36) {
  15. t[i] = s[i] - 35;
  16. }
  17. if (s[i] >= 48 && s[i] <= 57) {
  18. t[i] = s[i] - 46;
  19. }
  20. if (s[i] >= 65 && s[i] <= 90) {
  21. t[i] = s[i] - 53;
  22. }
  23. if (s[i] >= 97 && s[i] <= 122) {
  24. t[i] = s[i] - 59;
  25. }
  26. }
  27. s.clear();
  28. int c;
  29. for (int i = t.size() - 1; i >= 0; i--) {
  30. c = t[i];
  31. for (int i = 0; i < 6; i++) {
  32. if (c%2 == 0) {
  33. s.push_back('0');
  34. } else {
  35. s.push_back('1');
  36. }
  37. c /= 2;
  38. }
  39. }
  40. reverse(s.begin(), s.end());
  41. }
  42.  
  43. void pref_func(string& s) {
  44. p.resize(s.size());
  45. p[0] = 0;
  46. for (int i = 1; i < s.size(); i++) {
  47. p[i] = p[i - 1];
  48. while (p[i] > 0 && s[i] != s[p[i]]) {
  49. p[i] = p[p[i] - 1];
  50. }
  51. if (s[i] == s[p[i]]) {
  52. p[i]++;
  53. }
  54. }
  55. }
  56.  
  57. void solve() {
  58. string x, y;
  59. cin >> x >> y;
  60. conv(x);
  61. conv(y);
  62. string s = x + '&' + y + y;
  63. pref_func(s);
  64. for (int i = p.size() - 1; i > x.size() + y.size(); i--) {
  65. if (p[i] == x.size()) {
  66. cout << x.size() - (i - x.size() - y.size()) << '\n';
  67. return;
  68. }
  69. }
  70. cout << -1 << '\n';
  71. }
  72.  
  73. int main() {
  74. int m;
  75. cin >> k >> m;
  76. while (m--) {
  77. solve();
  78. }
  79. return 0;
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement