Submission #395176

#TimeUsernameProblemLanguageResultExecution timeMemory
395176wenqiGenetics (BOI18_genetics)C++14
0 / 100
564 ms109952 KiB
#include <bits/stdc++.h>

using namespace std;

int N, M, K;

using H = uint64_t;

#define P1 30881

const H P2 = (1ll << 45) - 1;

char dna[4169][4169];

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 idx[256];

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;

	idx['A'] = 0;
	idx['C'] = 1;
	idx['G'] = 2;
	idx['T'] = 3;

	for(int i = 0; i < M; i++) {
		vector<int> buckets[4];
		for(int j = 1; j <= N; j++) {
			int w = idx[dna[j][i]];
			buckets[w].push_back(j);
		}
		for (int ii = 0; ii < 4; ii++) {
			auto& A = buckets[ii];
			if(A.empty()) continue;
			W a, b;
			a.side = {A.begin(), A.end()};
			for(int iii = ii + 1; iii < 4; iii++) {
				auto& B = buckets[iii];
				b.side.insert(B.begin(), B.end());
			}
			a.c();
			b.c();
			if(b.side.empty())
				continue;
			bins.push_back({a, b});
		}
	}

	cout << 1 << '\n';

	return 0;

	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;
		}

		if(T == needed) {
			cout << i << '\n';
			return 0;
		}
	}
	return 0;
}

Compilation message (stderr)

genetics.cpp: In function 'int main()':
genetics.cpp:53:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   53 |    int w = idx[dna[j][i]];
      |                ~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...