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>
using namespace std;
string s[4105], t[4105];
map<string, int> mp;
bool bad[4105];
int diff (int x, int y) {
int cnt = 0;
for (int i = 0; i < (int) s[x].size(); i++) cnt += s[x][i] != s[y][i];
return cnt;
}
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> s[i];
mp[s[i]]++;
}
for (int i = 1; i <= n; i++) if (mp[s[i]] > 1) bad[i] = true;
deque<int> dq;
for (int i = 1; i <= n; i++) if (!bad[i]) {
while (i <= n && !dq.empty() && diff(dq.back(), i) != k) {
i++;
dq.pop_back();
}
if (i > n) break;
dq.push_back(i);
}
while ((int) dq.size() > 2) {
dq.pop_front();
dq.pop_back();
}
if ((int) dq.size() > 1) {
for (int i = 1; i <= n; i++) if (i != dq[0] && diff(i, dq[0]) != k) {
dq.pop_front();
break;
}
if ((int) dq.size() > 1) dq.pop_back();
}
cout << dq[0] << '\n';
return 0;
}
# | 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... |