제출 #404215

#제출 시각아이디문제언어결과실행 시간메모리
404215rama_pangGenetics (BOI18_genetics)C++17
100 / 100
526 ms25348 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N, M, K; cin >> N >> M >> K; const int MAX = 16405; vector<bitset<MAX>> A(N, 0); for (int i = 0; i < N; i++) { string s; cin >> s; for (int j = 0; j < M; j++) { if (s[j] == 'A') A[i][j * 4 + 0] = 1; if (s[j] == 'C') A[i][j * 4 + 1] = 1; if (s[j] == 'T') A[i][j * 4 + 2] = 1; if (s[j] == 'G') A[i][j * 4 + 3] = 1; } } // Turn input into binary string M = 4 * M; K = 2 * K; // bit 0 = -1 // bit 1 = +1 // Take \sum A[x][i] * A[y][i] // (M - K) - K = differ // differ = M - 2K K = M - 2 * K; mt19937 rnd(123456789); vector<int> weight(N); for (int i = 0; i < N; i++) { weight[i] = (rnd()) % (1ll << 30); } long long sum_weight = 0; vector<long long> sum(M); for (int i = 0; i < N; i++) { sum_weight += weight[i]; for (int j = 0; j < M; j++) { sum[j] += (A[i][j] == 0 ? -1 : 1) * weight[i]; } } for (int i = 0; i < N; i++) { long long hashed = 0; for (int j = 0; j < M; j++) { int sgn = (A[i][j] == 0 ? -1 : 1); hashed += 1ll * sgn * (sum[j] - sgn * weight[i]); } long long should_be = 1ll * (sum_weight - weight[i]) * K; if (hashed == should_be) { cout << i + 1 << '\n'; return 0; } } cout << -1 << '\n'; 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...