제출 #1124246

#제출 시각아이디문제언어결과실행 시간메모리
1124246_callmelucianGenetics (BOI18_genetics)C++17
100 / 100
758 ms17236 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tpl;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

ll rr (ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

const int mn = 5000;
const int MOD = 1e9 + 21;

int add (int a, int b) { return a + b - (a + b < MOD ? 0 : MOD); }

int sub (int a, int b) { return a - b + (a - b >= 0 ? 0 : MOD); }

int mul (int a, int b) { return 1LL * a * b % MOD; }

int ctoi (char c) {
    if (c == 'A') return 0;
    if (c == 'C') return 1;
    if (c == 'G') return 2;
    if (c == 'T') return 3;
}

int n, m, k;
string str[mn];
int key[mn], setHash[4][mn];
bool ans[mn];

void solve() {
    for (int i = 1; i <= max(n, m); i++) {
        key[i] = rr(1, MOD - 1);
        for (int j = 0; j < 4; j++) setHash[j][i] = 0;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int p = ctoi(str[i][j]);
            setHash[p][j] = add(setHash[p][j], key[i]);
        }
    }

    for (int i = 1; i <= n; i++) {
        int targHash = 0, foundHash = 0;
        for (int j = 1; j <= n; j++) {
            if (i == j) targHash = add(targHash, mul(m, key[j]));
            else targHash = add(targHash, mul(m - k, key[j]));
        }
        for (int j = 1; j <= m; j++) {
            int p = ctoi(str[i][j]);
            foundHash = add(foundHash, setHash[p][j]);
        }
//        cout << "try hash " << i << " " << foundHash << " " << targHash << "\n";
        if (foundHash != targHash) ans[i] = 0;
    }
}

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

    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++) {
        cin >> str[i];
        str[i] = " " + str[i];
    }
    for (int i = 1; i <= n; i++) ans[i] = 1;

    int TC = 3;
    while (TC--) solve();

    for (int i = 1; i <= n; i++)
        if (ans[i]) return cout << i, 0;

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

genetics.cpp: In function 'int ctoi(char)':
genetics.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
   33 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...