이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "dna.h"
using namespace std;
int n;
string dna1;
string dna2;
vector<pair<int, int>> as;
vector<pair<int, int>> cs;
vector<pair<int, int>> ts;
vector<int> c_a;
vector<int> c_t;
vector<int> a_c;
vector<int> a_t;
vector<int> t_c;
vector<int> t_a;
void init(std::string a, std::string b) {
n = a.size();
dna1 = a;
dna2 = b;
as.resize(n + 1, {0, 0});
cs.resize(n + 1, {0, 0});
ts.resize(n + 1, {0, 0});
c_a.resize(n + 1, 0);
c_t.resize(n + 1, 0);
a_c.resize(n + 1, 0);
a_t.resize(n + 1, 0);
t_c.resize(n + 1, 0);
t_a.resize(n + 1, 0);
for (int i = 1; i <= n; i++) {
as[i].first = as[i - 1].first + (dna1[i - 1] == 'A' ? 1 : 0);
as[i].second = as[i - 1].second + (dna2[i - 1] == 'A' ? 1 : 0);
cs[i].first = cs[i - 1].first + (dna1[i - 1] == 'C' ? 1 : 0);
cs[i].second = cs[i - 1].second + (dna2[i - 1] == 'C' ? 1 : 0);
ts[i].first = ts[i - 1].first + (dna1[i - 1] == 'T' ? 1 : 0);
ts[i].second = ts[i - 1].second + (dna2[i - 1] == 'T' ? 1 : 0);
c_a[i] = c_a[i - 1] + (dna2[i - 1] == 'C' && dna1[i - 1] == 'A' ? 1 : 0);
c_t[i] = c_t[i - 1] + (dna2[i - 1] == 'C' && dna1[i - 1] == 'T' ? 1 : 0);
a_c[i] = a_c[i - 1] + (dna2[i - 1] == 'A' && dna1[i - 1] == 'C' ? 1 : 0);
a_t[i] = a_t[i - 1] + (dna2[i - 1] == 'A' && dna1[i - 1] == 'T' ? 1 : 0);
t_c[i] = t_c[i - 1] + (dna2[i - 1] == 'T' && dna1[i - 1] == 'C' ? 1 : 0);
t_a[i] = t_a[i - 1] + (dna2[i - 1] == 'T' && dna1[i - 1] == 'A' ? 1 : 0);
}
}
int get_distance(int x, int y) {
if (as[y + 1].first - as[x].first != as[y + 1].second - as[x].second) return -1;
if (cs[y + 1].first - cs[x].first != cs[y + 1].second - cs[x].second) return -1;
if (ts[y + 1].first - ts[x].first != ts[y + 1].second - ts[x].second) return -1;
int ca = c_a[y + 1] - c_a[x];
int ct = c_t[y + 1] - c_t[x];
int ac = a_c[y + 1] - a_c[x];
int at = a_t[y + 1] - a_t[x];
int tc = t_c[y + 1] - t_c[x];
int ta = t_a[y + 1] - t_a[x];
int ans = 0, mn;
bool b = false;
mn = min(ca, ac);
ans += mn;
ca -= mn;
ac -= mn;
if ((ca || ac) && !b) {
b = true;
ans += 2 * max(ca, ac);
}
mn = min(ct, tc);
ans += mn;
ct -= mn;
tc -= mn;
if ((ct || tc) && !b) {
b = true;
ans += 2 * max(ct, tc);
}
mn = min(at, ta);
ans += mn;
at -= mn;
ta -= mn;
if ((at || ta) && !b) {
b = true;
ans += 2 * max(at, ta);
}
return ans;
}
# | 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... |