이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "dna.h"
using namespace std;
vector<tuple<int, int, int>> prefix1;
vector<tuple<int, int, int>> prefix2;
vector<vector<int>> prefix;
int n;
void init(string a, string b) {
n = a.size();
prefix.assign(n, vector<int> (6, 0));
prefix1.resize(n);
prefix2.resize(n);
for(int i = 0; i < n; i++){
if(i == 0){
prefix1[i] = {0, 0, 0};
prefix2[i] = {0, 0, 0};
if(a[i] == 'A'){
get<0> (prefix1[i])++;
}else if(a[i] == 'T'){
get<1>(prefix1[i])++;
}else get<2> (prefix1[i])++;
if(b[i] == 'A'){
get<0> (prefix2[i])++;
}else if(b[i] == 'T'){
get<1>(prefix2[i])++;
}else get<2> (prefix2[i])++;
}else{
prefix1[i] = prefix1[i - 1];
prefix2[i] = prefix2[i - 1];
if(a[i] == 'A'){
get<0> (prefix1[i])++;
}else if(a[i] == 'T'){
get<1>(prefix1[i])++;
}else get<2> (prefix1[i])++;
if(b[i] == 'A'){
get<0> (prefix2[i])++;
}else if(b[i] == 'T'){
get<1>(prefix2[i])++;
}else get<2> (prefix2[i])++;
}
if(i == 0){
if(a[i] != b[i]){
if(a[i] == 'A'){
if(b[i] == 'T') prefix[i][0]++;
else prefix[i][1]++;
}else if(a[i] == 'T'){
if(b[i] == 'A') prefix[i][2]++;
else prefix[i][3]++;
}else{
if(b[i] == 'A') prefix[i][4]++;
else prefix[i][5]++;
}
}
}else{
prefix[i] = prefix[i-1];
if(a[i] != b[i]){
if(a[i] == 'A'){
if(b[i] == 'T') prefix[i][0]++;
else prefix[i][1]++;
}else if(a[i] == 'T'){
if(b[i] == 'A') prefix[i][2]++;
else prefix[i][3]++;
}else{
if(b[i] == 'A') prefix[i][4]++;
else prefix[i][5]++;
}
}
}
}
}
int get_distance(int x, int y) {
int da, db;
if(x > 0) da = get<0> (prefix1[y]) - get<0> (prefix1[x-1]);
else da = get<0> (prefix1[y]);
if(x > 0) db = get<0> (prefix2[y]) - get<0> (prefix2[x-1]);
else db = get<0> (prefix2[y]);
if(da != db) return -1;
if(x > 0) da = get<1> (prefix1[y]) - get<1> (prefix1[x-1]);
else da = get<1> (prefix1[y]);
if(x > 0) db = get<1> (prefix2[y]) - get<1> (prefix2[x-1]);
else db = get<1> (prefix2[y]);
if(da != db) return -1;
if(x > 0) da = get<2> (prefix1[y]) - get<2> (prefix1[x-1]);
else da = get<2> (prefix1[y]);
if(x > 0) db = get<2> (prefix2[y]) - get<2> (prefix2[x-1]);
else db = get<2> (prefix2[y]);
if(da != db) return -1;
vector<int> v(6);
for(int i = 0; i < 6; i++){
if(x > 0) v[i] = prefix[y][i] - prefix[x-1][i];
else v[i] = prefix[y][i];
}
int ans = 0;
ans += min(v[1], v[4]);
int twos = max(v[1], v[4]) - min(v[1], v[4]);
ans += 2 * twos;
ans += min(v[0], v[2]);
ans += min(v[3], v[5]);
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... |