제출 #673960

#제출 시각아이디문제언어결과실행 시간메모리
673960Nahian9696DNA 돌연변이 (IOI21_dna)C++17
100 / 100
37 ms6168 KiB
#include "dna.h" using namespace std; #define f0(i,n) for(int32_t i = 0; i < (n); i++) #define f1(i,n) for(int32_t i = 1; i <= (n); i++) // all combination of A, T, C int AT[100005], AC[100005], TC[100005], TA[100005], CA[100005], CT[100005]; int n; void init(std::string a, std::string b) { n = a.size(); f0(i, n+1) { AT[i] = AC[i] = TC[i] = TA[i] = CA[i] = CT[i] = 0; } f0(i, n) { if (a[i] == 'A' && b[i] == 'T') AT[i+1]++; if (a[i] == 'A' && b[i] == 'C') AC[i+1]++; if (a[i] == 'T' && b[i] == 'C') TC[i+1]++; if (a[i] == 'T' && b[i] == 'A') TA[i+1]++; if (a[i] == 'C' && b[i] == 'A') CA[i+1]++; if (a[i] == 'C' && b[i] == 'T') CT[i+1]++; } f1(i, n) { AT[i] += AT[i-1]; AC[i] += AC[i-1]; TC[i] += TC[i-1]; TA[i] += TA[i-1]; CA[i] += CA[i-1]; CT[i] += CT[i-1]; } } int get_distance(int x, int y) { x++; y++; int at = AT[y] - AT[x-1]; int ac = AC[y] - AC[x-1]; int tc = TC[y] - TC[x-1]; int ta = TA[y] - TA[x-1]; int ca = CA[y] - CA[x-1]; int ct = CT[y] - CT[x-1]; int ans = 0; int min1 = min(at, ta); int min2 = min(ac, ca); int min3 = min(tc, ct); ans += min1 + min2 + min3; at -= min1; ta -= min1; ac -= min2; ca -= min2; tc -= min3; ct -= min3; if( (at == tc && tc == ca) && (ta == ac && ac == ct) ) { ans += at + ta + ac + ca; return ans; } else { // cout << at << " " << tc << " " << ca << endl; // cout << ta << " " << ac << " " << ct << endl; return -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...
#Verdict Execution timeMemoryGrader output
Fetching results...