This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dna.h"
#include <iostream>
#include <vector>
using namespace std;
string A,B;
vector<int> AT;
vector<vector<int>> vA,vB;
vector<vector<int>> acumA,acumB;
vector<int> acum;
void init(std::string a, std::string b) {
A = a;
B = b;
AT.assign(a.size(),0);
acum.assign(a.size(),0);
vA.assign(a.size(),vector<int>(3,0));
vB.assign(a.size(),vector<int>(3,0));
acumA.assign(a.size(),vector<int>(3,0));
acumB.assign(a.size(),vector<int>(3,0));
if (A[0] != B[0]) acum[0] = 1;
if (A[0] == 'T') acumA[0][0] = 1;
if (A[0] == 'A') acumA[0][1] = 1;
if (A[0] == 'C') acumA[0][2] = 1;
if (B[0] == 'T') acumB[0][0] = 1;
if (B[0] == 'A') acumB[0][1] = 1;
if (B[0] == 'C') acumB[0][2] = 1;
for (int i = 1; i < a.size(); i++)
{
if (A[i] == 'T') vA[i][0] = 1;
if (A[i] == 'A') vA[i][1] = 1;
if (A[i] == 'C') vA[i][2] = 1;
if (B[i] == 'T') vB[i][0] = 1;
if (B[i] == 'A') vB[i][1] = 1;
if (B[i] == 'C') vB[i][2] = 1;
if (A[i] != B[i])
{
AT[i] = 1;
}
acum[i] = acum[i-1]+AT[i];
acumA[i][0] = acumA[i-1][0]+ vA[i][0];
acumA[i][1] = acumA[i-1][1]+ vA[i][1];
acumA[i][2] = acumA[i-1][2]+ vA[i][2];
acumB[i][0] = acumB[i-1][0]+ vB[i][0];
acumB[i][1] = acumB[i-1][1]+ vB[i][1];
acumB[i][2] = acumB[i-1][2]+ vB[i][2];
}
}
int get_distance(int x, int y) {
/*int Amo[3] = {0,0,0};
int Amo2[3] = {0,0,0};
for (int i = x; i <= y; i++)
{
if (A[i] == 'T') Amo[0]++;
if (A[i] == 'A') Amo[1]++;
if (A[i] == 'C') Amo[2]++;
if (B[i] == 'T') Amo2[0]++;
if (B[i] == 'A') Amo2[1]++;
if (B[i] == 'C') Amo2[2]++;
}*/
int ta,tb,ca,cb,aa,ab;
if (x == 0)
{
ta = acumA[y][0];
tb = acumB[y][0];
aa = acumA[y][1];
ab = acumB[y][1];
ca = acumA[y][2];
cb = acumB[y][2];
}else
{
ta = acumA[y][0] - acumA[x-1][0];
tb = acumB[y][0] - acumB[x-1][0];
aa = acumA[y][1] - acumA[x-1][1];
ab = acumB[y][1] - acumB[x-1][1];
ca = acumA[y][2] - acumA[x-1][2];
cb = acumB[y][2] - acumB[x-1][2];
}
//cout<<ta<<" "<<aa<<" "<<ca<<endl;
//cout<<tb<<" "<<ab<<" "<<cb<<endl;
if ((y-x) <= 2)
{
if (ta == tb && aa == ab && ca == cb)
{
if ((y-x) == 0){
return 0;
}
if ((y-x) == 1)
{
if (A[x] == B[x]) return 0;
return 1;
}
if (A[x] == B[x] && A[x+1] == B[x+1])
{
return 0;
}
if (A[x] == B[x] || A[x+1] == B[x+1] || A[y] == B[y])
{
return 1;
}
return 2;
}else
{
return -1;
}
}
if (ca == cb && ca == 0 && ta == tb && aa == ab)
{
int dif;
if (x == 0)
{
dif = (acum[y]);
}else
{
dif = (acum[y]-acum[x-1]);
}
return dif/2;
}else
{
return -1;
}
return 0;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i = 1; i < a.size(); i++)
| ~~^~~~~~~~~~
# | 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... |