Submission #1128159

#TimeUsernameProblemLanguageResultExecution timeMemory
1128159underwaterkillerwhaleGenetics (BOI18_genetics)C++20
46 / 100
2094 ms23924 KiB
//#include"holiday.h"
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define REB(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }

const int N = 5e3 + 7;
const int Mod = 1e9 + 7;///lon
const ll INF = 1e18 + 7;
const ll BASE = 137;
const int szBL = 450;

vector<char> ch = {'A', 'C', 'G', 'T'};

int n, m, K;
string s[N];
int Col[N][255];

void solution() {
    cin >> n >> m >> K;
    rep (i, 1, n) {
        cin >> s[i];
    }
    rep (j, 0, m - 1) {
        rep (i, 1, n) Col[j][s[i][j]]++;
    }
    vector<int> cand;
    rep (i, 1, n) {
        int res = 0;
        rep (j, 0, m - 1) {
            iter (&c, ch) {
                if (c != s[i][j]) res += Col[j][c];
            }
        }
        if (res == K * (n - 1)) cand.pb(i);
    }
    random_shuffle(ALL(cand));
    auto Distance = [&] (int i, int j) -> int {
        int res = 0;
        rep (k, 0, m - 1) {
            if (s[i][k] != s[j][k]) ++res;
        }
        return res;
    };
    iter (&i, cand) {
        bool ok = 1;
        rep (j, 1, n) {
            if (i != j && Distance(i, j) != K) {
                ok = 0;
                break;
            }
        }
        if (ok) {
            cout << i <<"\n";
            return;
        }
    }
}

#define file(name) freopen(name".inp","r",stdin); \
freopen(name".out","w",stdout);
int main () {
//    file("c");
    ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}
/*
no bug challenge +36
10 2
1 2 3 1 4 5 1 2 1 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
1 10
4 9
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...