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;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 4005;
string s[N];
int n, m, k;
bool used[N];
int calc(int i, int j) {
int res = 0;
for (int x = 0; x < m; x++)
res += s[i][x] != s[j][x];
return res;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> k;
vector<int> x, y;
for (int i = 0; i < n; i++) {
cin >> s[i];
if (x.empty()) x.push_back(i);
else y.push_back(i);
while (x.size() && y.size()) {
if (calc(x.back(), y.back()) == k) {
if (!used[y.back()])
x.push_back(y.back());
y.pop_back();
} else {
used[x.back()] = true;
x.pop_back();
}
}
}
for (int i : x) {
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
shuffle(ord.begin(), ord.end(), rng);
bool flag = true;
for (int j : ord)
if (i != j && calc(i, j) != k) {
flag = false; break;
}
if (flag) return cout << i + 1, 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... |