Submission #140811

#TimeUsernameProblemLanguageResultExecution timeMemory
140811MinnakhmetovGenetics (BOI18_genetics)C++14
47 / 100
1438 ms92792 KiB
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
const int N = 4105, K = 2;
string s[N], let = "ACGT";
int a[N], b[N][K], mem[N][N];
bool banned[N];
 
bitset<N> w[K][N];
 
signed main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int n, m, k;
    cin >> n >> m >> k;
 
    mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
    for (int i = 0; i < n; i++) {
        a[i] = i;
        while (s[i].empty())
            getline(cin, s[i]);
        for (int j = 0; j < m; j++) {
            s[i][j] = find(all(let), s[i][j]) - let.begin();
            b[j][s[i][j]]++;
            w[s[i][j]][i][j] = 1;
        }
    }
 
    for (int i = 0; i < m; i++) {
        int sum = 0;
        for (int j = 0; j < K; j++) {
            sum += b[i][j];
        }
        for (int j = 0; j < K; j++) {
            b[i][j] = sum - b[i][j];
        }
    }
 
    shuffle(a, a + n, rng);
 
    memset(mem, -1, sizeof(mem));
 
    for (int h = 0; h < n; h++) {
        int i = a[h];
 
        if (banned[i])
            continue;
 
        ll sum = 0;
        for (int j = 0; j < m; j++) {
            sum += b[j][s[i][j]];
        }
 
        if (sum != k * (n - 1))
            continue;
 
        bool ok = true;
        for (int j = 0; j < n; j++) {
            if (i != j) {
                if (mem[i][j] == -1) {
                    mem[i][j] = m;
                    for (int h = 0; h < K; h++) {
                        mem[i][j] -= (w[h][i] & w[h][j]).count();
                    }
                    mem[j][i] = mem[i][j];
                }
                
                if (mem[i][j] != k) {
                    banned[j] = 1;
                    ok = false;
                }
            }
        }
        if (ok) {
            cout << i + 1;
            return 0;
        }
    }
    
    return 0;
}

Compilation message (stderr)

genetics.cpp: In function 'int main()':
genetics.cpp:33:25: warning: array subscript has type 'char' [-Wchar-subscripts]
             b[j][s[i][j]]++;
                         ^
genetics.cpp:34:22: warning: array subscript has type 'char' [-Wchar-subscripts]
             w[s[i][j]][i][j] = 1;
                      ^
genetics.cpp:60:32: warning: array subscript has type 'char' [-Wchar-subscripts]
             sum += b[j][s[i][j]];
                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...