제출 #604310

#제출 시각아이디문제언어결과실행 시간메모리
604310stevancvDNA 돌연변이 (IOI21_dna)C++17
100 / 100
45 ms10068 KiB
#include <bits/stdc++.h> #include "dna.h" #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 1e5 + 2; int pa[N][3], pb[N][3], pc[N][3][3]; void init(string s, string t) { int n = s.size(); vector<int> a(n), b(n); for (int i = 0; i < n; i++) { if (s[i] == 'A') a[i] = 0; if (s[i] == 'C') a[i] = 1; if (s[i] == 'T') a[i] = 2; if (t[i] == 'A') b[i] = 0; if (t[i] == 'C') b[i] = 1; if (t[i] == 'T') b[i] = 2; } for (int i = 0; i < n; i++) { pa[i][a[i]]++; pb[i][b[i]]++; pc[i][a[i]][b[i]]++; if (i > 0) { for (int j = 0; j < 3; j++) { pa[i][j] += pa[i - 1][j]; pb[i][j] += pb[i - 1][j]; for (int jj = 0; jj < 3; jj++) { pc[i][j][jj] += pc[i - 1][j][jj]; } } } } } int Geta(int l, int r, int i) { int ans = pa[r][i]; if (l > 0) ans -= pa[l - 1][i]; return ans; } int Getb(int l, int r, int i) { int ans = pb[r][i]; if (l > 0) ans -= pb[l - 1][i]; return ans; } int Get(int l, int r, int i, int j) { int ans = pc[r][i][j]; if (l > 0) ans -= pc[l - 1][i][j]; return ans; } int get_distance(int l, int r) { for (int i = 0; i < 3; i++) if (Geta(l, r, i) != Getb(l, r, i)) return -1; int ans = 0; int rest = 0; for (int i = 0; i < 3; i++) { for (int j = i + 1; j < 3; j++) { int x = min(Get(l, r, i, j), Get(l, r, j, i)); ans += x; rest = max(Get(l, r, i, j), Get(l, r, j, i)) - x; } } return ans + 2 * rest; }
#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...