이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |