Submission #895655

#TimeUsernameProblemLanguageResultExecution timeMemory
895655pccGenetics (BOI18_genetics)C++14
27 / 100
71 ms63256 KiB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt")

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

const int mxn = 4140;
int arr[mxn][mxn];
int N,M,K;
vector<int> v,cand;
const int magic = 20;
bitset<mxn> in;
const int lim = 1.95*CLOCKS_PER_SEC;
int st;

int dif(int a,int b){
	int re = 0;
	for(int i = 0;i<M;i++){
		re += (arr[a][i] != arr[b][i]);
	}
	return re;
}

void collect(){
	for(int i = 0;i<N;i++){
		for(int j = i+1;j<N;j++){
			if(dif(i,j) != K){
				if(!in[i])v.push_back(i);
				if(!in[j])v.push_back(j);
				if(v.size()>=magic)return;
				in[i] = in[j] = true;
			}
		}
		if(!in[i]){
			cout<<i+1;
			exit(0);
		}
	}
	return;
}

int main(){
	st = clock();
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M>>K;
	for(int i = 0;i<N;i++){
		for(int j = 0;j<M;j++){
			char c;
			cin>>c;
			arr[i][j] = c-'A';
		}
	}
	collect();
	for(int i = 0;i<N;i++){
		if(in[i])continue;
		bool flag = true;
		for(auto &j:v){
			if(dif(i,j) != K)flag = false;
		}
		if(flag)cand.push_back(i);
	}
	assert(cand.size()<100);
	for(auto &i:cand){
		bool flag = true;
		for(int j = 0;j<N;j++){
			if(i == j)continue;
			if(dif(i,j) != K){
				flag = false;
				break;
			}
		}
		if(flag){
			cout<<i+1;
			return 0;
		}
	}
	assert(false);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...