Submission #984484

#TimeUsernameProblemLanguageResultExecution timeMemory
984484Mizo_CompilerGenetics (BOI18_genetics)C++17
100 / 100
388 ms36608 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC target("popcnt") typedef long long ll; #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define sz(x) int(x.size()) const int N = 4100, M[] = {int(1e9+7), 998244353}, B = 2; const ll P[] = {4, 5}; int n, m, k, id[30]; ll pw[N][B], sum[B], val[N][B], cnt[N][4][B]; string s[N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m >> k; id[int('A'-'A')] = 0; id[int('G'-'A')] = 2; id[int('T'-'A')] = 3; id[int('C'-'A')] = 1; for (int i = 0; i < B; i++) { pw[0][i] = 1; for (int j = 1; j < N; j++) { pw[j][i] = (pw[j-1][i] * P[i]) % M[i]; } } for (int i = 0; i < n; i++) { cin >> s[i]; for (int j = 0; j < m; j++) { for (int kk = 0; kk < B; kk++) { val[i][kk] += (ll(id[int(s[i][j]-'A')]+1) * pw[j][kk]) % M[kk]; if (val[i][kk] >= M[kk])val[i][kk] -= M[kk]; } } for (int j = 0; j < m; j++) { for (int kk = 0; kk < B; kk++) { cnt[j][id[int(s[i][j]-'A')]][kk] += val[i][kk]; if (cnt[j][id[int(s[i][j]-'A')]][kk] >= M[kk])cnt[j][id[int(s[i][j]-'A')]][kk] -= M[kk]; } } for (int j = 0; j < B; j++) { sum[j] += val[i][j]; if (sum[j] >= M[j])sum[j] -= M[j]; } } for (int i = 0; i < n; i++) { ll sm[B] = {0, 0}, sm2[B] = {0, 0}; for (int j = 0; j < B; j++) { sm[j] = sum[j] - val[i][j]; if (sm[j] < 0)sm[j] += M[j]; sm[j] = (sm[j] * ll(m-k)) % M[j]; } bool f = true; for (int j = 0; j < m; j++) { for (int kk = 0; kk < B; kk++) { sm2[kk] += cnt[j][id[int(s[i][j]-'A')]][kk]; if (sm2[kk] >= M[kk])sm2[kk] -= M[kk]; sm2[kk] -= val[i][kk]; if (sm2[kk] < 0)sm2[kk] += M[kk]; } } for (int j = 0; j < B; j++) { f &= (sm[j] == sm2[j]); } if (f) { cout << i+1; return 0; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...