#include <bits/stdc++.h>
using namespace std;
const int N = 510;
char s[N][N], s1[N][N];
int n, k, l, r;
unsigned long long a[N];
set <pair<unsigned long long, int> > ss;
int main()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
scanf("%s", s[i] + 1);
memcpy(s1[i], s[i], sizeof s1[i]);
sort(s[i] + 1, s[i] + 1 + n);
for (int j = 1; j <= n; j++)
{
a[i] *= 127;
a[i] += s[i][j];
}
ss.insert(make_pair(a[i], i));
}
for (auto i : ss)
{
auto it = ss.upper_bound(i);
if (it == ss.end())
break;
if ((*it).first == i.first)
{
l = INT_MAX;
r = 0;
for (int j = 1; j <= n; j++)
if (s1[i.second][j] != s1[(*it).second][j])
l = min(l, j), r = max(r, j);
if (r - l < k)
return printf("DA"), 0;
}
}
printf("NE");
return 0;
}
哈希