# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
979896 | vjudge1 | Genetics (BOI18_genetics) | C++17 | 843 ms | 83388 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 4'123;
const ll Mod = 1'696'969'997;
const ll maxW = 1'234'567;
mt19937_64 rng(Mod);
uniform_int_distribution<ll> uid(1, maxW);
ll madd(ll x, ll y) { return (x + y) % Mod; }
ll msub(ll x, ll y) { return (x - y + Mod) % Mod; }
ll mmul(ll x, ll y) { return (x * y) % Mod; }
char id[256];
int N, M, K;
int A[maxN][maxN];
ll sum_w, row_w[maxN];
ll col_sum[4][maxN];
int main() {
id['A'] = 0; id['C'] = 1; id['G'] = 2; id['T'] = 3;
scanf("%d %d %d", &N, &M, &K);
char buf;
for (int i = 1; i <= N; i++) {
row_w[i] = uid(rng);
sum_w = madd(sum_w, row_w[i]);
for (int j = 1; j <= M; j++) {
scanf(" %c", &buf);
A[i][j] = id[buf];
}
}
for (int c = 0; c < 4; c++) {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
if (A[i][j] == c) col_sum[c][j] = madd(col_sum[c][j], row_w[i]);
}
}
}
for (int r = 1; r <= N; r++) {
ll target = mmul(M - K, msub(sum_w, row_w[r])); // must match at M - K positions
ll cur = 0;
for (int c = 1; c <= M; c++) {
cur = madd(cur, msub(col_sum[A[r][c]][c], row_w[r]));
}
if (target == cur) {
printf("%d\n", r);
exit(0);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |