This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define N 100500
#define oo ll(1e16)
#define ft first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define el '\n'
#define elf endl
#define base ll(1e9 + 7)
using namespace std;
typedef long long ll;
typedef long double ld;
int n, k;
int pf[501][501][26];
string s[N];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// in("input.txt");
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> s[i];
for (int j = 0; j < n; j++) {
for (int t = 0; t < 26; t++)
pf[i][j][t] = (j - 1 < 0 ? 0 : pf[i][j - 1][t]);
pf[i][j][s[i][j] - 'a']++;
}
}
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
bool f = 1;
for (int t = 0; t < 26; t++)
if ((pf[i][n - 1][t] == 0 && pf[j][n - 1][t] != 0) || (pf[i][n - 1][t] != 0 && pf[j][n - 1][t] == 0))
f = 0;
if (!f)
continue;
f = 0;
for (int t = 0; t + k - 1 < n && !f; t++) {
bool gd = 1;
for (int l = 0; l < 26 && gd; l++)
if ((pf[i][t + k - 1][l] - (t - 1 < 0 ? 0 : pf[i][t - 1][l])) != (pf[j][t + k - 1][l] - (t - 1 < 0 ? 0 : pf[j][t - 1][l])))
gd = 0;
f |= gd;
}
if (f) {
cout << "DA";
return 0;
}
}
cout << "NE";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |