fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pi pair<int,int>
  4. #define pii pair<pi,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define F first
  8. #define S second
  9. #define all(x) x.begin(), x.end()
  10. #define sortall(x) sort(all(x))
  11. #define lli long long int
  12. #define f(i,a,b) for (lli i = a; i <= b; i++)
  13. #define fr(i,a,b) for (lli i = a; i >= b; i--)
  14. #define mod 1000000007
  15. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  16.  
  17. vector<lli> a, b;
  18. lli n, m;
  19.  
  20. string funBinary(lli fuck)
  21. {
  22. string s = bitset<64> (fuck).to_string();
  23. const auto loc1 = s.find('1');
  24. if (loc1 != string::npos)
  25. return s.substr(loc1);
  26. return "0";
  27. }
  28. lli dp[10005][10005];
  29. lli getMaxCommon()
  30. {
  31. f(i, 0, n)
  32. f(j, 0, m)
  33. dp[i][j] = 0;
  34. // memset(dp, 0, sizeof(dp));
  35. fr(i, n - 1, 0)
  36. fr(j, m - 1, 0)
  37. {
  38. if (a[i] == b[j])
  39. dp[i][j] = dp[i + 1][j + 1] + 1;
  40. }
  41. lli mx = 0;
  42. f(i, 0, n - 1)
  43. f(j, 0, m - 1)
  44. mx = max(mx, dp[i][j]);
  45. return mx;
  46. }
  47.  
  48. void solve()
  49. {
  50. cin >> n >> m;
  51. a.resize(n);
  52. b.resize(m);
  53. string strA, strB;
  54. f(i, 0, n - 1)
  55. cin >> a[i];
  56. cin >> strA;
  57. f(i, 0, m - 1)
  58. cin >> b[i];
  59. cin >> strB;
  60. lli k = getMaxCommon();
  61. lli aa, bb, result;
  62.  
  63. bb = (lli)strB[k - 1];
  64. aa = (lli)strA[k - 1];
  65.  
  66. result = (aa ^ bb);
  67.  
  68. cout << funBinary(result);
  69. cout << "\n";
  70. }
  71. int main()
  72. {
  73. IOS;
  74. lli t;
  75. cin >> t;
  76. while (t--)
  77. solve();
  78. return 0;
  79. }
Success #stdin #stdout 0s 4536KB
stdin
1
3 4
1 2 3
abc
2 3 4 5
pqrs
stdout
10011