# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
395167 | wenqi | Genetics (BOI18_genetics) | C++14 | 2097 ms | 317704 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;
int N, M, K;
#define P1 30881
#define P2 54877ll
char dna[4169][4169];
using H = uint32_t;
H coef[4169];
struct W {
unordered_set<int> side;
H hash;
void c() {
hash = 0;
for (int i : side) {
hash = (hash + coef[i]) % P2;
}
}
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M >> K;
coef[0] = 1;
for(int i = 1; i <= N; i++) {
cin >> dna[i];
coef[i] = (coef[i - 1] * P1) % P2;
}
vector<pair<W, W>> bins;
for(int i = 0; i < M; i++) {
vector<int> buckets[256];
for(int j = 1; j <= N; j++) {
int w = dna[j][i];
buckets[w].push_back(j);
}
const char* R = "ACGT";
for (int ii = 0; ii < 4; ii++) {
for(int iii = ii + 1; iii < 4; iii++) {
auto& A = buckets[R[ii]];
auto& B = buckets[R[iii]];
W a, b;
a.side = {A.begin(), A.end()};
b.side = {B.begin(), B.end()};
a.c();
b.c();
bins.push_back({a, b});
}
}
}
for (int i = 1; i <= N; i++) {
H needed = 0;
for(int j = 1; j <= N; j++) {
if(i == j) continue;
needed = (needed + coef[j] * K) % P2;
}
H T = 0;
for(auto p : bins) {
if(p.first.side.find(i) != p.first.side.end()) {
T += p.second.hash;
}else if(p.second.side.find(i) != p.second.side.end()) {
T += p.first.hash;
}
T %= P2;
}
#ifdef DEBUG
cerr << T << ' ' << needed << '\n';
#endif
if(T == needed) {
cout << i << '\n';
return 0;
}
}
return 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... |