제출 #594087

#제출 시각아이디문제언어결과실행 시간메모리
594087ZaniteGenetics (BOI18_genetics)C++17
0 / 100
297 ms53516 KiB
// I am now here, but I have yet to prove that I am worthy of my place here.

#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using ll	= long long;

const ll maxN	= 4101;

const ll mod	= 1'690'758'499;
const ll maxW	= 420'000;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll getRand(ll l, ll r) {
	return uniform_int_distribution<ll>(l, r)(rng);
}

inline void maddto(ll &x, ll y) {x += y; if (x > mod) x -= mod;}

inline ll msub(ll x, ll y) {x -= y; if (x < 0) x += mod; return x;}
inline ll mmul(ll x, ll y) {x *= y; x %= mod; return x;}

ll N, M, K;
ll DNA[4][maxN][maxN];
ll corr[256];
char buf;

ll w[maxN], sumW;
ll columnSum[4][maxN];

int main() {
	corr[(ll)'A'] = 0;
	corr[(ll)'C'] = 1;
	corr[(ll)'G'] = 2;
	corr[(ll)'T'] = 3;

	scanf("%lld %lld %lld", &N, &M, &K);
	K = M - K;

	for (ll i = 1; i <= N; i++) {
		for (ll j = 1; j <= M; j++) {
			scanf(" %c", &buf);
			DNA[corr[(ll)buf]][i][j] = 1;
		}

		w[i] = getRand(1, maxW);
		maddto(sumW, w[i]);
	}

	for (ll j = 1; j <= M; j++) {
		for (ll d = 0; d < 4; d++) {
			for (ll i = 1; i <= N; i++) {
				maddto(columnSum[d][j], w[i] * DNA[d][i][j]);
			}
		}
	}

	for (ll comp = 1; comp <= N; comp++) {
		ll target = mmul(K, msub(sumW, w[comp]));
		ll total = 0;
		for (ll d = 0; d < 4; d++) {
			for (ll col = 1; col <= N; col++) {
				maddto(total, mmul(DNA[d][comp][col], msub(columnSum[d][col], mmul(w[comp], DNA[d][comp][col]))));
			}
		}

		if (target == total) {
			printf("%lld\n", comp);
			return 0;
		}
	}
}

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

genetics.cpp: In function 'int main()':
genetics.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%lld %lld %lld", &N, &M, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
genetics.cpp:46:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |    scanf(" %c", &buf);
      |    ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...