이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "dna.h"
using namespace std;
const int MAXN = 1e5 + 7;
int slowo1[MAXN];
int slowo2[MAXN];
int pref[MAXN][3][3];
void init(string a, string b)
{
int n = a.size();
// zamiana znakow na liczby
for (int i = 0; i < n; i++) {
if (a[i] == 'A')
slowo1[i + 1] = 0;
if (a[i] == 'T')
slowo1[i + 1] = 1;
if (a[i] == 'C')
slowo1[i + 1] = 2;
if (b[i] == 'A')
slowo2[i + 1] = 0;
if (b[i] == 'T')
slowo2[i + 1] = 1;
if (b[i] == 'C')
slowo2[i + 1] = 2;
}
// liczenie sum prefiksowych
for (int i = 1; i <= n; i++) {
for (int c1 = 0; c1 < 3; c1++) {
for (int c2 = 0; c2 < 3; c2++) {
// jezeli mamy c1 w slowo1 oraz c2 w slowo2
if ((slowo1[i] == c1) && (slowo2[i] == c2))
pref[i][c1][c2] = pref[i - 1][c1][c2] + 1;
else
pref[i][c1][c2] = pref[i - 1][c1][c2] + 0;
}
}
}
}
int get_distance(int x, int y)
{
x = x + 1;
y = y + 1;
int AT = pref[y][0][1] - pref[x - 1][0][1];
int TA = pref[y][1][0] - pref[x - 1][1][0];
int TC = pref[y][1][2] - pref[x - 1][1][2];
int CT = pref[y][2][1] - pref[x - 1][2][1];
int CA = pref[y][2][0] - pref[x - 1][2][0];
int AC = pref[y][0][2] - pref[x - 1][0][2];
// jezeli mamy tyle samo A, T, C w obu podslowach
if ((AT + AC == TA + CA) && (TA + TC == AT + CT)) {
int wynik = min(AT, TA) + min(TC, CT) + min(CA, AC);
wynik += 2 * abs(AT - TA);
return wynik;
}
else {
return -1;
}
}
# | 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... |