이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
map <char, int> hashValue;
hashValue['A'] = 1; hashValue['C'] = 2; hashValue['G'] = 3; hashValue['T'] = 4;
int n, m, k;
cin >> n >> m >> k;
vector <vector <int>> matrixEncode(n, vector <int> (m));
vector <long long> weightHash(n);
vector <vector <long long>> sumOfColumn(m, vector <long long> (5, 0));
long long totalWeight = 0; // sum (weightHash[i]) for i in 0 -> n - 1
vector <int> indexMatching;
for (int i = 0; i < n; i++) {
string series;
cin >> series;
for (int j = 0; j < m; j++)
matrixEncode[i][j] = hashValue[series[j]];
}
for (int i = 0; i < n; i++) {
weightHash[i] = rand();
totalWeight += weightHash[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++)
sumOfColumn[j][matrixEncode[i][j]] += weightHash[i];
}
for (int i = 0; i < n; i++) {
long long hashValue1 = 0, hashValue2 = 0;
// Approach 1: Row view
hashValue1 = (totalWeight - weightHash[i]) * k;
// Approach 2: Column view
for (int j = 0; j < m; j++) {
for (int c = 1; c <= 4; c++) {
if (matrixEncode[i][j] != c)
hashValue2 += sumOfColumn[j][c];
}
}
if (hashValue1 == hashValue2)
indexMatching.push_back(i);
}
if (indexMatching.empty()) {
cout << -1;
return 0;
}
// Spurious hit --> Checking again
for (auto &index: indexMatching) {
bool checkValid = true;
for (int i = 0; i < n; i++) {
if (i == index)
continue;
int countDifferent = 0;
for (int j = 0; j < m; j++)
countDifferent += (matrixEncode[index][j] != matrixEncode[i][j]);
checkValid &= (countDifferent == k);
if (checkValid == false)
break;
}
if (checkValid) {
cout << (index + 1);
return 0;
}
}
// Miss hit --> Actual fake!
cout << -1;
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... |