제출 #1042463

#제출 시각아이디문제언어결과실행 시간메모리
1042463vjudge1DNA 돌연변이 (IOI21_dna)C++17
100 / 100
37 ms8884 KiB
#include <bits/stdc++.h> #include "dna.h" using namespace std; vector<long long> at, ac, ca, ct, ta, tc; void init(string a,string b) { int n = a.size() + 1; a = '#' + a; b = '#' + b; at.resize(n + 1, 0); ac.resize(n + 1, 0); ca.resize(n + 1, 0); ct.resize(n + 1, 0); ta.resize(n + 1, 0); tc.resize(n + 1, 0); for(int i = 1; i <= n; ++i) { ac[i] = ac[i - 1]; at[i] = at[i - 1]; ca[i] = ca[i - 1]; ct[i] = ct[i - 1]; ta[i] = ta[i - 1]; tc[i] = tc[i - 1]; if(a[i] == 'A') { if(b[i] == 'C') ac[i]++; if(b[i] == 'T') at[i]++; } if(a[i] == 'C') { if(b[i] == 'A') ca[i]++; if(b[i] == 'T') ct[i]++; } if(a[i] == 'T') { if(b[i] == 'A') ta[i]++; if(b[i] == 'C') tc[i]++; } } } int get_distance(int x, int y) { int ans = 0; int acc = ac[y + 1] - ac[x]; int att = at[y + 1] - at[x]; int caa = ca[y + 1] - ca[x]; int ctt = ct[y + 1] - ct[x]; int taa = ta[y + 1] - ta[x]; int tcc = tc[y + 1] - tc[x]; if(acc + att != taa + caa) {return -1;} if(caa + ctt != acc + tcc) {return -1;} if(taa + tcc != att + ctt) {return -1;} int mn1 = min(acc,caa), mn2 = min(att,taa), mn3 = min(tcc,ctt); ans += mn1 + mn2 + mn3; acc -= mn1; caa -= mn1; att -= mn2; taa -= mn2; tcc -= mn3; ctt -= mn3; int sum = max({att, taa, ctt, tcc, acc, caa}); ans += sum * 2; return ans; }
#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...