이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <algorithm>
using namespace std;
int n;
char a[100005], b[100005];
int acnt[100005], tcnt[100005], ccnt[100005];
int at[100005], ta[100005], ac[100005],
ca[100005], ct[100005], tc[100005];
void init(std::string x, std::string y) {
n = (int)x.size();
for (int i = 0; i < n; i++) a[i+1] = x[i];
for (int i = 0; i < n; i++) b[i+1] = y[i];
for (int i = 1; i <= n; i++) {
acnt[i] = acnt[i-1] + (a[i] == 'A' ? 1 : 0) - (b[i] == 'A' ? 1 : 0);
tcnt[i] = tcnt[i-1] + (a[i] == 'T' ? 1 : 0) - (b[i] == 'T' ? 1 : 0);
ccnt[i] = ccnt[i-1] + (a[i] == 'C' ? 1 : 0) - (b[i] == 'C' ? 1 : 0);
at[i] = at[i-1] + (a[i] == 'A' && b[i] == 'T' ? 1 : 0);
ta[i] = ta[i-1] + (a[i] == 'T' && b[i] == 'A' ? 1 : 0);
ac[i] = ac[i-1] + (a[i] == 'A' && b[i] == 'C' ? 1 : 0);
ca[i] = ca[i-1] + (a[i] == 'C' && b[i] == 'A' ? 1 : 0);
ct[i] = ct[i-1] + (a[i] == 'C' && b[i] == 'T' ? 1 : 0);
tc[i] = tc[i-1] + (a[i] == 'T' && b[i] == 'C' ? 1 : 0);
}
}
int get_distance(int x, int y) {
x++; y++;
int adiff = acnt[y] - acnt[x-1];
int tdiff = tcnt[y] - tcnt[x-1];
int cdiff = ccnt[y] - ccnt[x-1];
if (adiff != 0 || tdiff != 0 || cdiff != 0) return -1;
int n_at = at[y] - at[x-1];
int n_ta = ta[y] - ta[x-1];
int n_ac = ac[y] - ac[x-1];
int n_ca = ca[y] - ca[x-1];
int n_ct = ct[y] - ct[x-1];
int n_tc = tc[y] - tc[x-1];
int min1 = min(n_at, n_ta);
int min2 = min(n_ac, n_ca);
int min3 = min(n_ct, n_tc);
n_at -= min1; n_ta -= min1;
n_ac -= min2; n_ca -= min2;
n_ct -= min3; n_tc -= min3;
return min1 + min2 + min3 + 2 * max(n_at, n_ta);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |