Submission #722098

#TimeUsernameProblemLanguageResultExecution timeMemory
722098Jarif_RahmanGenetics (BOI18_genetics)C++17
0 / 100
10 ms8932 KiB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

unordered_map<char, int> dna = {{'A', 0}, {'T', 1}, {'C', 2}, {'G', 3}};

int n, m, k;
vector<bool> candidate;
str s[4100];

int comp(int a, int b){
    int c = 0;
    for(int i = 0; i < m; i++) if(s[a][i] != s[b][i]) c++;
    return c;
}

int ans = -1;
void dfs(int nd){
    if(ans != -1) return;
    if(!candidate[nd]) return;
    int nxt = -1;
    bool ok = 1;
    for(int i = 0; i < n; i++) if(i != nd){
        int c = comp(i, nd);
        if(c == k){
            nxt = i;
            if(!ok){
                dfs(i);
                break;
            }
        }
        else{
            ok = 0;
            candidate[nd] = 0;
            candidate[i] = 0;
            if(nxt != -1){
                dfs(nxt);
                break;
            }
        }
    }
    if(ok){
        ans = nd;
        return;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m >> k;
    for(int i = 0; i < n; i++) cin >> s[i];
    vector<vector<int>> cnt(n, vector<int>(4, 0));
    for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cnt[j][dna[s[i][j]]]++;

    candidate.assign(n, 1);
    for(int i = 0; i < n; i++){
        int c = 0;
        for(int j = 0; j < m; j++) for(int x = 0; x < 4; x++) if(x != dna[s[i][j]]) c+=cnt[j][x];
        if(c != (n-1)*k) candidate[i] = 0;
    }

    for(int i = 0; i < n; i++) if(candidate[i]){
        dfs(i);
        break;
    }

    cout << ans+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...