이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
int A1[100005], T1[100005], C1[100005];
int A2[100005], T2[100005], C2[100005];
int AT[100005], AC[100005], TA[100005], TC[100005], CA[100005], CT[100005];
void init(std::string a, std::string b) {
for (int i = 0; i < a.size(); i++) {
if (i > 0) {
A1[i] = A1[i - 1];
T1[i] = T1[i - 1];
C1[i] = C1[i - 1];
A2[i] = A2[i - 1];
T2[i] = T2[i - 1];
C2[i] = C2[i - 1];
AT[i] = AT[i - 1];
AC[i] = AC[i - 1];
TA[i] = TA[i - 1];
TC[i] = TC[i - 1];
CA[i] = CA[i - 1];
CT[i] = CT[i - 1];
}
A1[i] += a[i] == 'A' ? 1 : 0;
T1[i] += a[i] == 'T' ? 1 : 0;
C1[i] += a[i] == 'C' ? 1 : 0;
A2[i] += b[i] == 'A' ? 1 : 0;
T2[i] += b[i] == 'T' ? 1 : 0;
C2[i] += b[i] == 'C' ? 1 : 0;
if (a[i] != b[i]) {
if (b[i] == 'A') {
TA[i] += a[i] == 'T' ? 1 : 0;
CA[i] += a[i] == 'C' ? 1 : 0;
} else {
if (b[i] == 'T') {
AT[i] += a[i] == 'A' ? 1 : 0;
CT[i] += a[i] == 'C' ? 1 : 0;
} else {
AC[i] += a[i] == 'A' ? 1 : 0;
TC[i] += a[i] == 'T' ? 1 : 0;
}
}
}
}
}
int get_distance(int x, int y) {
int dA, dT, dC, dist = 0;
dA = (A1[y] - (x == 0 ? 0 : A1[x - 1])) - (A2[y] - (x == 0 ? 0 : A2[x - 1]));
dT = (T1[y] - (x == 0 ? 0 : T1[x - 1])) - (T2[y] - (x == 0 ? 0 : T2[x - 1]));
dC = (C1[y] - (x == 0 ? 0 : C1[x - 1])) - (C2[y] - (x == 0 ? 0 : C2[x - 1]));
if (dA != 0 || dT != 0 || dC != 0) {
return -1;
}
int at = AT[y] - (x == 0 ? 0 : AT[x - 1]);
int ac = AC[y] - (x == 0 ? 0 : AC[x - 1]);
int ta = TA[y] - (x == 0 ? 0 : TA[x - 1]);
int tc = TC[y] - (x == 0 ? 0 : TC[x - 1]);
int ca = CA[y] - (x == 0 ? 0 : CA[x - 1]);
int ct = CT[y] - (x == 0 ? 0 : CT[x - 1]);
if (at >= ta) {
dist += ta;
at -= ta;
ta = 0;
} else {
dist += at;
ta -= at;
at = 0;
}
if (tc >= ct) {
dist += ct;
tc -= ct;
ct = 0;
} else {
dist += tc;
ct -= tc;
tc = 0;
}
if (ca >= ac) {
dist += ac;
ca -= ac;
ac = 0;
} else {
dist += ca;
ac -= ca;
ca = 0;
}
dist += 2 * (at + ac + ta + tc + ca + ct) / 3;
return dist;
}
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
# | 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... |