This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll inf = 1e18;
const int M = 4100;
random_device rd;
int main() {
srand(time(0));
cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, m, k;
cin >> n >> m >> k;
vector<string> a(n);
for (string &s: a) cin >> s;
bool sub2 = true;
for (int i = 0; i < n and sub2; i++) for (char x: a[i]) sub2 &= x == 'A' or x == 'C';
if (sub2) {
vector<bitset<M>> bs(n);
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (a[i][j] == 'A') bs[i].set(j);
vector ok(n, vector(n, -1));
vector<int> pos(n);
iota(pos.begin(), pos.end(), 0);
shuffle(pos.begin(), pos.end(), rd);
for (int i = 0; i < min(15, n); i++) {
for (int j = 0; j < n; j++) {
if (pos[i] == j) continue;
if ((bs[pos[i]] ^ bs[j]).count() != k) {
ok[pos[i]][j] = ok[j][pos[i]] = 0;
}
}
}
for (int i = 0; i < n; i++) {
if (count(ok[i].begin(), ok[i].end(), 0)) continue;
for (int j = 0; j < n; j++) {
if (i == j or ok[i][j] == 1) continue;
if ((bs[i] ^ bs[j]).count() != k) {
ok[i][j] = ok[j][i] = 0;
break;
} else {
ok[i][j] = ok[j][i] = 1;
}
}
if (!count(ok[i].begin(), ok[i].end(), 0)) {
cout << i + 1;
return 0;
}
}
}
for (int i = 0; i < n; i++) {
bool ok = true;
for (int j = 0; j < n and ok; j++) {
if (i == j) continue;
int cnt = 0;
for (int p = 0; p < m and cnt <= k; p++) cnt += a[i][p] != a[j][p];
ok &= cnt == k;
}
if (ok) {
cout << i + 1;
return 0;
}
}
}
Compilation message (stderr)
genetics.cpp: In function 'int main()':
genetics.cpp:35:50: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
35 | if ((bs[pos[i]] ^ bs[j]).count() != k) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
genetics.cpp:44:45: warning: comparison of integer expressions of different signedness: 'std::size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
44 | if ((bs[i] ^ bs[j]).count() != k) {
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# | 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... |