제출 #600859

#제출 시각아이디문제언어결과실행 시간메모리
600859Valaki2DNA 돌연변이 (IOI21_dna)C++17
0 / 100
134 ms34480 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; #define a A #define b B #define x X #define y Y #define pb push_back int n; vector<int> a; vector<int> b; vector<vector<int> > pref_cnt_a; vector<vector<int> > pref_cnt_b; vector<vector<vector<int> > > pref; void solve() { pref_cnt_a.assign(1 + n, vector<int> (3, 0)); pref_cnt_b.assign(1 + n, vector<int> (3, 0)); for(int i = 1; i <= n; i++) { pref_cnt_a[i] = pref_cnt_a[i - 1]; pref_cnt_a[i][a[i]]++; pref_cnt_b[i] = pref_cnt_b[i - 1]; pref_cnt_b[i][b[i]]++; } pref.assign(1 + n, vector<vector<int> > (3, vector<int> (3, 0))); for(int i = 1; i <= n; i++) { pref[i] = pref[i - 1]; pref[i][a[i]][b[i]]++; } } int query(int l, int r) { int res = 0; vector<int> cnt_a(3, 0); vector<int> cnt_b(3, 0); for(int i = 0; i < 3; i++) { cnt_a[i] = pref_cnt_a[r][i] - pref_cnt_a[l - 1][i]; cnt_b[i] = pref_cnt_b[r][i] - pref_cnt_b[l - 1][i]; if(cnt_a[i] != cnt_b[i]) { return -1; } } vector<vector<int> > v(3, vector<int> (3, 0)); for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { v[i][j] = pref[r][i][j] - pref[l - 1][i][j]; } } int mini = -1; mini = min(v[0][1], v[1][0]); res += mini; v[0][1] -= mini; v[1][0] -= mini; mini = min(v[2][1], v[1][2]); res += mini; v[2][1] -= mini; v[1][2] -= mini; mini = min(v[0][2], v[2][0]); res += mini; v[0][2] -= mini; v[2][0] -= mini; mini = -1; int maxi = 0; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { maxi = max(maxi, v[i][j]); } } res += 2 * maxi; return res; } #undef a #undef b #undef x #undef y void init(string a, string b) { n = a.size(); A.assign(n + 1, 0); B.assign(n + 1, 0); for(int i = 1; i <= n; i++) { if(a[i - 1] == 'A') { A[i] = 0; } if(a[i - 1] == 'T') { A[i] = 1; } if(a[i - 1] == 'C') { A[i] = 2; } if(b[i - 1] == 'A') { B[i] = 0; } if(b[i - 1] == 'T') { B[i] = 1; } if(b[i - 1] == 'C') { B[i] = 2; } } solve(); } int get_distance(int x, int y) { return query(x + 1, y + 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...