Submission #473703

#TimeUsernameProblemLanguageResultExecution timeMemory
473703ZaZo_Genetics (BOI18_genetics)C++14
100 / 100
1187 ms20940 KiB
#include <bits/stdc++.h>
#define ZAZO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
using namespace std;
// i have maximum 65 chuncks , each chuck will have 64 bits (elements)
unsigned long long bits[4100][65],bits2[4100][65];
int n , m , k ;
bool check(int x , int y)
{
  int cnt=0;
  for(int i = 0 ; i < 65 ; i++)
  cnt += __builtin_popcountll((bits[x][i]^bits[y][i])|(bits2[x][i]^bits2[y][i]));
  if(cnt == k) return true;
  return false;
}

int32_t main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  ZAZO
  cin >> n >> m >> k;
  int for_hamatcha[n];
  for(int i = 0 ; i < n ; i++)
  {
    for_hamatcha[i]=i;
    for(int j = 0 ; j < m ; j ++)
    {
      char s; cin >> s;
      // get the bit you want by checking mod
      unsigned long long pos = ((unsigned long long) 1<<j%64);
      // set the bit to one in the specific place in the specific chunk;
      if(s == 'C') bits[i][j/64] |= pos;
      else if(s == 'T') bits[i][j/64] |= pos , bits2[i][j/64] |= pos;
      else if(s == 'G') bits2[i][j/64] |= pos;
    }
  }
  shuffle(for_hamatcha,for_hamatcha+n,rng);
  int ans[n]={0};
  for(int i = 0 ; i < n ; i ++)
  {
    if(ans[for_hamatcha[i]]==-1) continue;
    int flg=0;
    for(int j = 0 ; j < n ; j ++)
    {
      if(for_hamatcha[i]==for_hamatcha[j]) continue;
      bool ok = check(for_hamatcha[i] , for_hamatcha[j]);
      if(!ok)
      {
        flg=1;
        ans[for_hamatcha[i]]=-1;
        ans[for_hamatcha[j]]=-1;
        break;
      }
    }
    if(!flg){
      cout<<for_hamatcha[i]+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...