Submission #404206

#TimeUsernameProblemLanguageResultExecution timeMemory
404206rama_pangGenetics (BOI18_genetics)C++17
27 / 100
2062 ms5952 KiB
#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 = 4105;
  vector<vector<bitset<MAX>>> A(4, vector<bitset<MAX>>(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[0][i][j] = 1;
      if (s[j] == 'C') A[1][i][j] = 1;
      if (s[j] == 'T') A[2][i][j] = 1;
      if (s[j] == 'G') A[3][i][j] = 1;
    }
  }

  bitset<MAX> candidates = 0;
  for (int i = 0; i < N; i++) {
    candidates[i] = 1;
  }

  mt19937 rnd(MAX);
  vector<int> ord(N);
  iota(begin(ord), end(ord), 0);

  while (candidates.count() > 1) {
    shuffle(begin(ord), end(ord), rnd);
    for (int i = 0; i + 1 < N; i++) {
      int x = ord[i + 0];
      int y = ord[i + 1];
      int differ = M;
      for (int j = 0; j < 4; j++) {
        differ -= (A[j][x] & A[j][y]).count();
      }
      if (differ != K) {
        candidates[x] = 0;
        candidates[y] = 0;
      }
    }
  }

  cout << (candidates._Find_first() + 1)  << '\n';
  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...