이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
int dp1[3][100100], dp2[3][100100];
int dp[3][3][100100];
char h[26];
void init(std::string a, std::string b) {
h[0] = 0;
h['T' - 'A'] = 1;
h['C' - 'A'] = 2;
for (int i = 1;i <= (int)a.size();i++) {
char c = a[i - 1];
dp1[0][i] = dp1[0][i - 1] + (c == 'A');
dp1[1][i] = dp1[1][i - 1] + (c == 'T');
dp1[2][i] = dp1[2][i - 1] + (c == 'C');
}
for (int i = 1;i <= (int)b.size();i++) {
char c = b[i - 1];
dp2[0][i] = dp2[0][i - 1] + (c == 'A');
dp2[1][i] = dp2[1][i - 1] + (c == 'T');
dp2[2][i] = dp2[2][i - 1] + (c == 'C');
}
for (int i = 1;i <= (int)a.size();i++) {
for (int j = 0;j < 3;j++) {
for (int k = 0;k < 3;k++) {
dp[j][k][i] = dp[j][k][i - 1] + (h[a[i - 1] - 'A'] == j && h[b[i - 1] - 'A'] == k);
}
}
}
}
int get_distance(int x, int y) {
int l = x, r = y;
r++, l++;
bool ch = 1;
for (int k = 0;k < 3;k++) {
ch &= (dp1[k][r] - dp1[k][l - 1] == dp2[k][r] - dp2[k][l - 1]);
}
if (!ch) {
return -1;
}
int now[3][3] = {};
for (int i = 0;i < 3;i++) {
for (int j = 0;j < 3;j++) {
now[i][j] = dp[i][j][r] - dp[i][j][l - 1];
}
}
int cnt = 0;
for (int i = 0;i < 3;i++) {
for (int j = i + 1;j < 3;j++) {
int mn;
if (now[i][j] > now[j][i]) mn = now[j][i];
else mn = now[i][j];
cnt += mn;
now[i][j] -= mn;
now[j][i] -= mn;
}
}
int cnt2 = 0;
for (int i = 0;i < 3;i++) {
for (int j = 0;j < 3;j++) {
if (i == j) continue;
cnt2 += now[i][j];
}
}
return cnt + cnt2 * 2 / 3;
}
# | 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... |