제출 #95834

#제출 시각아이디문제언어결과실행 시간메모리
95834caesar2001Genetics (BOI18_genetics)C++14
46 / 100
2157 ms808364 KiB
#include <bits/stdc++.h> #define ll long long #define lsb(x) (x & -x) using namespace std; struct Data { int from, to, cost; }; void transpune(const vector<vector<ll>> &v, vector<vector<ll>> &ans, int n, int m) { for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) ans[j][i] = v[i][j]; } void multiply(const vector<vector<ll>> &a, const vector<vector<ll>> &b, vector<vector<ll>> &ans, int n, int m, int p) { for(int i = 1; i <= n; i ++) for(int j = 1; j <= p; j ++) for(int k = 1; k <= m; k ++) ans[i][j] += (a[i][k] * b[k][j]); } void add(vector<vector<ll>> &ans, const vector<vector<ll>> &a, int n, int m) { for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) ans[i][j] += a[i][j]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("a.in", "r", stdin); //freopen("a.out", "w", stdout); int n, m, k; cin >> n >> m >> k; k = m - k; vector<int> code(30, 0); code['A' - 'A'] = 1; code['C' - 'A'] = 2; code['G' - 'A'] = 3; code['T' - 'A'] = 4; vector<vector<vector<ll>>> v(5, vector<vector<ll>> (n + 1, vector<ll> (m + 1, 0))); for(int i = 1; i <= n; i ++) { string s; cin >> s; for(int j = 0; j < m; j ++) v[code[s[j] - 'A']][i][j + 1] = 1; } srand(time(NULL)); vector<vector<ll>> hs(n + 1, vector<ll> (2, 0)); for(int i = 1; i <= n; i ++) hs[i][1] = rand(); vector<vector<ll>> ans(n + 1, vector<ll> (2, 0)); for(int i = 1; i <= 4; i ++) { vector<vector<ll>> t(m + 1, vector<ll> (n + 1, 0)); transpune(v[i], t, n, m); vector<vector<ll>> ths(m + 1, vector<ll> (2, 0)); multiply(t, hs, ths, m, n, 1); vector<vector<ll>> aux(n + 1, vector<ll> (2, 0)); multiply(v[i], ths, aux, n, m, 1); add(ans, aux, n, 1); } vector<vector<ll>> sol(n + 1, vector<ll> (n + 1, k)); for(int i = 1; i <= n; i ++) sol[i][i] = m; vector<vector<ll>> solhs(n + 1, vector<ll> (2, 0)); multiply(sol, hs, solhs, n, n, 1); for(int i = 1; i <= n; i ++) { if(solhs[i][1] == ans[i][1]) { cout << i; return 0; } } 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...