Submission #949890

#TimeUsernameProblemLanguageResultExecution timeMemory
949890fuad27Genetics (BOI18_genetics)C++17
46 / 100
2032 ms90196 KiB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int N=4200;
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
bitset<N> b[N][2];
int dif[N][N];
int diff(int i, int j) {
  if(dif[i][j]>=0)return dif[i][j];
  return dif[i][j]=((b[i][0]^b[j][0])|(b[i][1]^b[j][1])).count();
}
int main () {
  cin.tie(0)->sync_with_stdio(0);
  int n, m, k;
  cin >> n >> m >> k;
  memset(dif, -1, sizeof dif);
  string a[n];
  for(int i =0 ;i<n;i++) {
    cin >> a[i];
    for(int j =0 ;j<m;j++) {
      if(a[i][j]=='A') {
        b[i][0][j]=b[i][1][j]=1;
      }
      else if(a[i][j]=='C') {
        b[i][0][j]=1;
        b[i][1][j]=0;
      }
      else if(a[i][j]=='G') {
        b[i][0][j]=0;
        b[i][1][j]=1;
      }
    }
  }
  bool check[n];
  memset(check, 0, sizeof check);
  queue<int> que;
  for(int i = 0;i<n;i++)que.push(i);
  while(que.size()>1) {
    int at=que.front();
    que.pop();
    if(check[at])continue;
    int c=rng()%n;
    while(c==at) {
      c=rng()%n;
    }
    if(diff(at, c)!=k) {
      check[at]=check[c]=1;
      continue;
    }
    else que.push(at);
  }
  cout << que.front()+1 << "\n";

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...