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 int int64_t
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ar = array<int, 2>;
const int64_t INF = 1ll << 60;
const int N = 4200;
int n, m, k;
vector<int> a;
string s[N];
bool get(const string &s1, const string &s2) {
int x = 0;
FOR(i, 0, m) {
x += s1[i] != s2[i];
if (x > k) return false;
}
return x == k;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> k;
a.resize(n);
FOR (i, 0, n) {
cin >> s[i];
}
iota(a.begin(), a.end(), 0);
mt19937 rng((int64_t) new char);
int cnt = 0;
while (a.size() >= 2 && cnt <= 10) {
int i = rng() % a.size(), j;
do {
j = rng() % a.size();
} while (j == i);
if (!get(s[a[i]], s[a[j]])) {
if (i > j) swap(i, j);
a.erase(a.begin() + j);
a.erase(a.begin() + i);
cnt = 0;
}
++cnt;
}
FOR(i, 0, a.size()) {
const string S = s[a[i]];
bool f = true;
FOR(j, 0, n) if (j != a[i])
f &= get(S, s[j]);
if (f) {
cout << a[i] + 1;
return 0;
}
}
return 0;
}
Compilation message (stderr)
genetics.cpp: In function 'int main()':
genetics.cpp:3:42: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
3 | #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
| ^
genetics.cpp:49:9: note: in expansion of macro 'FOR'
49 | FOR(i, 0, a.size()) {
| ^~~
# | 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... |