Submission #822311

#TimeUsernameProblemLanguageResultExecution timeMemory
822311qqspeed20015Genetics (BOI18_genetics)C++14
47 / 100
339 ms83088 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['B'] = 2; hashValue['C'] = 3; hashValue['D'] = 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 int x = indexMatching.size(); 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) { cout << (index + 1); return 0; } } // Miss hit --> Actual fake! cout << -1; return 0; }

Compilation message (stderr)

genetics.cpp: In function 'int main()':
genetics.cpp:58:9: warning: unused variable 'x' [-Wunused-variable]
   58 |     int x = indexMatching.size();
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...