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 n, m, k, id[4105];
mt19937 r (chrono::high_resolution_clock().now().time_since_epoch().count());
int rnd (int mn, int mx) {
return uniform_int_distribution<int> (mn, mx) (r);
}
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 solve () {
for (int i = n; i >= 1; i--) {
int swp = rnd(1, i);
swap(s[i], s[swp]);
swap(id[i], id[swp]);
}
for (int i = 1; i <= n; i++) bad[i] = mp[s[i]] > 1;
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) {
if (diff(dq.front(), dq.back()) == k) return solve();
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();
}
return id[dq[0]];
}
int main () {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> s[i];
id[i] = i;
mp[s[i]]++;
}
cout << solve() << '\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... |