This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;
int n, m, k, c[N], combined_sum = 0, d[N][4];
string s[N];
void solve(){
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
cin >> n >> m >> k;
for(int i = 0; i < n; ++i){
cin >> s[i];
for(int j = 0; j < m; ++j){
if(s[i][j] == 'A') s[i][j] = '0';
if(s[i][j] == 'G') s[i][j] = '1';
if(s[i][j] == 'T') s[i][j] = '2';
if(s[i][j] == 'C') s[i][j] = '3';
}
}
for(int i = 0; i < n; ++i){
c[i] = uniform_int_distribution<int>(0, 1000)(rng);
combined_sum += c[i] * k;
}
for(int j = 0; j < m; ++j) d[j][0] = d[j][1] = d[j][2] = d[j][3] = 0;
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
d[j][s[i][j] - '0'] += c[i];
}
}
for(int i = 0; i < n; ++i){
int sum = 0;
for(int j = 0; j < m; ++j){
for(int l = 0; l < 4; ++l){
if(l == s[i][j] - '0') continue;
sum += d[j][l];
}
}
if(sum == combined_sum - c[i] * k){
bool ok = 1;
for(int j = 0; j < n; ++j){
if(i == j) continue;
int dif = 0;
for(int l = 0; l < m; ++l){
if(s[j][l] != s[i][l]) dif++;
}
if(dif != k) ok = 0;
}
if(ok){
cout << i + 1;
return;
}
}
}
cout << -1;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
cout << '\n';
}
return 0;
}
Compilation message (stderr)
genetics.cpp: In function 'int main()':
genetics.cpp:75:16: warning: unused variable 'aa' [-Wunused-variable]
75 | int T = 1, aa;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |