贪心:考虑可移动与不可移动的情况,利用字符数量判断
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n, k;
std::cin >> n >> k;
std::string s, t;
std::cin >> s >> t;
int cnt[26] {};
for (int i = 0; i < n; i ++) {
if (i - k < 0 && i + k >= n) {
if (s[i] != t[i]) {
std::cout << "NO\n";
return;
}
} else {
cnt[s[i] - 'a'] += 1;
cnt[t[i] - 'a'] -= 1;
}
}
for (int i = 0; i < 26; i ++) {
if (cnt[i]) {
std::cout << "NO\n";
return;
}
}
std::cout << "YES\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}