Submission #95152

#TimeUsernameProblemLanguageResultExecution timeMemory
95152popovicirobertGenetics (BOI18_genetics)C++14
100 / 100
311 ms27288 KiB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXN = 4100;

char str[MAXN + 1][MAXN + 1];
ll hsh[MAXN + 1], sum[MAXN + 1][4];

int pos[256];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n, m, k;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    srand(time(NULL));
    cin >> n >> m >> k;
    ll tot = 0;
    for(i = 1; i <= n; i++) {
        cin >> str[i] + 1;
        hsh[i] = rand();
        tot += hsh[i];
    }
    pos['A'] = 0;
    pos['C'] = 1;
    pos['G'] = 2;
    pos['T'] = 3;
    for(j = 1; j <= m; j++) {
        for(i = 1; i <= n; i++) {
            sum[j][pos[str[i][j]]] += hsh[i];
        }
    }
    for(i = 1; i <= n; i++) {
        ll cur = 0;
        for(j = 1; j <= m; j++) {
            cur += sum[j][pos[str[i][j]]];
        }
        if(cur - m * hsh[i] == (tot - hsh[i]) * (m - k)) {
            cout << i;
            return 0;
        }
    }
    //cin.close();
    //cout.close();
    return 0;
}

Compilation message (stderr)

genetics.cpp: In function 'int main()':
genetics.cpp:28:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         cin >> str[i] + 1;
                ~~~~~~~^~~
genetics.cpp:38:33: warning: array subscript has type 'char' [-Wchar-subscripts]
             sum[j][pos[str[i][j]]] += hsh[i];
                                 ^
genetics.cpp:44:40: warning: array subscript has type 'char' [-Wchar-subscripts]
             cur += sum[j][pos[str[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...