제출 #822322

#제출 시각아이디문제언어결과실행 시간메모리
822322qqspeed20015Genetics (BOI18_genetics)C++14
100 / 100
427 ms83064 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...