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<pair<string, int>> a, tmp;
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) {
string s;
cin >> s;
a[i] = {s, i};
}
mt19937 rng((int64_t) new char);
tmp = a;
//shuffle(a.begin(), a.end(), rng);
while (a.size() >= 10) {
int i = rng() % a.size(), j;
do {
j = rng() % a.size();
} while (j == i);
if (!get(a[i].first, a[j].first)) {
if (i > j) swap(i, j);
a.erase(a.begin() + j);
a.erase(a.begin() + i);
}
}
FOR(i, 0, a.size()) {
bool f = true;
for (auto &[s, x]: tmp) if (x != a[i].second)
f &= get(a[i].first, s);
if (f) {
cout << a[i].second + 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<std::pair<std::__cxx11::basic_string<char>, 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:48:9: note: in expansion of macro 'FOR'
48 | 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... |