이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <vector>
#include <cassert>
using namespace std;
struct matrix{
int vl[3][3];
matrix(){
for(int i = 0; i < 3; ++i){
for(int j = 0; j < 3; ++j)
vl[i][j] = 0;
}
}
int* operator[](int i){
return vl[i];
}
matrix operator-(matrix m) const {
matrix ans;
for(int i = 0; i < 3; ++i){
for(int j = 0; j < 3; ++j){
ans[i][j] = vl[i][j] - m[i][j];
}
}
return ans;
}
int geteval(){
int ans = 0;
int sm[3] = {0, 0, 0};
for(int i = 0; i < 3; ++i){
for(int j = 0; j < 3; ++j){
sm[i] += vl[i][j];
sm[j] -= vl[i][j];
}
}
for(int i = 0; i < 3; ++i)
if(sm[i] != 0)
return -1;
for(int i = 0; i < 3; ++i){
for(int j = i + 1; j < 3; ++j){
int p = min(vl[i][j], vl[j][i]);
ans += p;
vl[i][j] -= p;
vl[j][i] -= p;
}
}
int cnt0 = 0;
for(int j = 0; j < 3; ++j)
cnt0 += vl[0][j];
return ans + cnt0 * 2;
}
};
const int MAXN = 1e5 + 123;
matrix pfm_[MAXN];
matrix* pfm = pfm_ + 1;
vector<int> cnvt(string a){
int n = a.size();
vector<int> ans(n);
for(int i = 0; i < n; ++i){
if(a[i] == 'A')
ans[i] = 0;
if(a[i] == 'C')
ans[i] = 1;
if(a[i] == 'T')
ans[i] = 2;
}
return ans;
}
void init(string a_, string b_){
vector<int> a = cnvt(a_);
vector<int> b = cnvt(b_);
int n = a.size();
for(int i = 0; i < n; ++i){
pfm[i] = pfm[i - 1];
if(a[i] != b[i]){
++pfm[i][a[i]][b[i]];
}
}
}
int get_distance(int x, int y) {
++y;
return (pfm[y - 1] - pfm[x - 1]).geteval();
}
# | 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... |