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;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, M, K;
cin >> N >> M >> K;
const int MAX = 16405;
vector<bitset<MAX>> A(N, 0);
for (int i = 0; i < N; i++) {
string s;
cin >> s;
for (int j = 0; j < M; j++) {
if (s[j] == 'A') A[i][j * 4 + 0] = 1;
if (s[j] == 'C') A[i][j * 4 + 1] = 1;
if (s[j] == 'T') A[i][j * 4 + 2] = 1;
if (s[j] == 'G') A[i][j * 4 + 3] = 1;
}
}
// Turn input into binary string
M = 4 * M;
K = 2 * K;
mt19937 rnd(123456789);
vector<int> weight(N);
for (int i = 0; i < N; i++) {
weight[i] = (rnd()) % (1ll << 30);
}
long long sum_weight = 0;
vector<long long> sum0(M);
vector<long long> sum1(M);
for (int i = 0; i < N; i++) {
sum_weight += weight[i];
for (int j = 0; j < M; j++) {
(A[i][j] == 0 ? sum0[j] : sum1[j]) += weight[i];
}
}
for (int i = 0; i < N; i++) {
long long hashed = 0;
for (int j = 0; j < M; j++) {
hashed += (A[i][j] == 0 ? sum1[j] : sum0[j]);
}
long long should_be = 1ll * (sum_weight - weight[i]) * K;
if (hashed == should_be) {
bool ok = true;
for (int j = 0; j < N; j++) if (i != j) {
int differ = (A[i] ^ A[j]).count();
if (differ != K) {
ok = false;
break;
}
}
if (ok) {
cout << i + 1 << '\n';
return 0;
}
}
}
cout << -1 << '\n';
return 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... |