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;
const int N = 4107, L = 26, K = 66, MOD = 1000000007;
char s[N][N];
int main() {
// freopen("input.txt", "r", stdin);
// ios::sync_with_stdio(false); cin.tie(0);
int n, m, k;
scanf("%d%d%d\n", &n, &m, &k);
vector <int> ord(n), rnk(n, 0);
iota(ord.begin(), ord.end(), 0);
for (int i = 0; i < n; ++i) {
scanf("%s\n", s[i]);
}
auto diff = [&](int x, int y) {
int ans = 0;
for (int i = 0; i < m; ++i) {
ans += s[x][i] != s[y][i];
}
return ans;
};
for (int it = 0; it < 3; ++it) {
for (int i = 0; i + 1 < (int)ord.size(); ++i) {
if (diff(ord[i], ord[i + 1]) != k) {
++i;
continue;
}
rnk[ord[i]] = 1;
rnk[ord[i + 1]] = 1;
}
sort(ord.begin(), ord.end(), [&](int x, int y) { return rnk[x] > rnk[y]; });
while (ord.size() > 1 && rnk[ord.back()] == 0) ord.pop_back();
for (auto it : ord) rnk[it] = 0;
random_shuffle(ord.begin(), ord.end());
}
for (int j = 0; j < (int)ord.size(); ++j) {
int x = ord[j];
bool ok = true;
for (int i = 0; i < n && ok; ++i) {
if (i == x) continue;
if (diff(x, i) != k) ok = false;
}
if (ok) { cout << x + 1 << '\n'; break; }
}
return 0;
}
Compilation message (stderr)
genetics.cpp: In function 'int main()':
genetics.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d%d%d\n", &n, &m, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%s\n", s[i]);
| ~~~~~^~~~~~~~~~~~~~
# | 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... |