Advertisement
aquiem

curious students

Feb 17th, 2024
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. ll mod = 1e9 + 7;
  6.  
  7. int main()
  8. {
  9. ll t;
  10. cin >> t;
  11. while (t--)
  12. {
  13. ll n, k;
  14. cin >> n >> k;
  15. string a, b;
  16. cin >> a >> b;
  17.  
  18. bool good = true;
  19. for (int i = 0; i + k - 1 < n; i++)
  20. {
  21. vector<ll> final1(26,0), final2(26,0);
  22. for (int j = i; j < i + k; j++)
  23. {
  24. final1[((int)a[j]) - 97]++;
  25. final2[((int)b[j]) - 97]++;
  26. }
  27. for (int j = 0; j < 26; j++)
  28. {
  29. if (final1[j] != final2[j])
  30. {
  31. good = false;
  32. }
  33. }
  34. }
  35.  
  36. if (good)
  37. {
  38. cout << "YES\n";
  39. continue;
  40. }
  41. cout << "NO\n";
  42. }
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement