Submission #518850

#TimeUsernameProblemLanguageResultExecution timeMemory
518850IerusGenetics (BOI18_genetics)C++17
100 / 100
1306 ms41960 KiB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
//#define int short
#define S second
#define sz(x) (int)x.size()
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

random_device(rd);
mt19937 rng(rd());
const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
const int N = 4102;
const bool I = 1;

int n, m, k;
char a[N][N];
bitset<N> bin[4][N];
int cnt[4][N];
int sum[N][4];
template<class T> T randomize(T mod){
	return (uniform_int_distribution<T>(0, mod - 1))(rng);
}

int get(char a){
	if(a == 'A') return 0;
	if(a == 'C') return 1;
	if(a == 'G') return 2;
	return 3;
}
signed main(){
	NFS;
	cin >> n >> m >> k;
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < m; ++j){
			cin >> a[i][j];
			bin[get(a[i][j])][i][j] = true;
			++sum[j][get(a[i][j])];
		}
		cnt[0][i] = bin[0][i].count();
		cnt[1][i] = bin[1][i].count();
		cnt[2][i] = bin[2][i].count();
		cnt[3][i] = bin[3][i].count();
	}
//	for(int x = 0; x <= 3; ++ x){
//		cerr <<"x: " << x << '\n';
//		for(int j = 0; j < m; ++j){
//			cerr << sum[j][x] << ' ';
//		}
//		cerr << '\n';
//	}
	vector <int> f, s;
	for(int i = 1; i <= n; ++i){
		f.pb(i);
		s.pb(i);
	}
	for(int i = 0; i < n; ++i){
		swap(f[i], f[randomize(n)]);
		swap(s[i], s[randomize(n)]);
	}
//	cerr << "F\n";
//	for(int i : f){
//		cerr  << i << ' ';
//	}cerr << '\n';
//	cerr << "S\n";
//	for(int i : s){
//		cerr  << i << ' ';
//	}cerr << '\n';
	
	for(int i : f){
		int kol = 0;
		for(int j = 0; j < m; ++j){
			kol += n - sum[j][get(a[i][j])];
		}
//		cerr << "i: " << i << " -> " << kol << '\n';
		if(kol != (n - 1) * k){
			continue;
		}
		bool ok = true;
		for(int j : s){
			if(i == j) continue;
			int sm = 0;
			for(int x = 0; x < 4; ++x){
				sm += cnt[x][i] - (bin[x][i] & bin[x][j]).count();
			}
//			cerr << "j: " << j << " -> " << sm << '\n';
			if(sm != k){
				ok = false;
				break;
			}
		}
		if(ok){
			cout << i;
			return 0;	
		}
	}
};
 
 
 

Compilation message (stderr)

genetics.cpp:16:14: warning: unnecessary parentheses in declaration of 'rd' [-Wparentheses]
   16 | random_device(rd);
      |              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...