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 <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
map<string, int> typ = {{"AT",0},{"AC",1},{"TA",2},{"TC",3},{"CA",4},{"CT",5},{"AA",6},{"TT",7},{"CC",8}};
map<char, int> znak = {{'A',0},{'T',1},{'C',2}};
int pref_typ[100001][9];
int pref_znak[100001][2][3];
int n;
void init(string s1, string s2)
{
n = (int)s1.size();
rep(i,n)
{
// cout << znak[s1[i]] << " znak s1\n";
rep(j,3)
{
if(znak[s1[i]] == j) pref_znak[i+1][0][znak[s1[i]]] = pref_znak[i][0][znak[s1[i]]] +1;
else pref_znak[i+1][0][j] = pref_znak[i][0][j];
}
}
rep(i,n)
{
rep(j,3)
{
if(znak[s2[i]] == j) pref_znak[i+1][1][znak[s2[i]]] = pref_znak[i][1][znak[s2[i]]] +1;
else pref_znak[i+1][1][j] = pref_znak[i][1][j];
}
}
rep(i,n)
{
rep(z,9)
{
string s; s += s1[i]; s+= s2[i];
if(typ[s] == z) pref_typ[i+1][z] = pref_typ[i][z] +1;
else pref_typ[i+1][z] = pref_typ[i][z];
}
}
}
int get_distance(int p, int k)
{
int T1 = pref_znak[k+1][0][znak['T']] - pref_znak[p][0][znak['T']];
int C1 = pref_znak[k+1][0][znak['C']] - pref_znak[p][0][znak['C']];
int A1 = pref_znak[k+1][0][znak['A']] - pref_znak[p][0][znak['A']];
int T2 = pref_znak[k+1][1][znak['T']] - pref_znak[p][1][znak['T']];
int C2 = pref_znak[k+1][1][znak['C']] - pref_znak[p][1][znak['C']];
int A2 = pref_znak[k+1][1][znak['A']] - pref_znak[p][1][znak['A']];
// cout << T1 << " " << C1 << " " << A1 << " " << T2 << " " << C2 << " " << A2 << " dane\n";
if(T1 != T2 || C1 != C2 || A1 != A2)
{
return -1;
}
int ust = k-p+1;
int ans = 0;
ust -= pref_typ[k+1][typ["AA"]] - pref_typ[p][typ["AA"]];
ust -= pref_typ[k+1][typ["TT"]] - pref_typ[p][typ["TT"]];
ust -= pref_typ[k+1][typ["CC"]] - pref_typ[p][typ["CC"]];
int AC = pref_typ[k+1][typ["AC"]] - pref_typ[p][typ["AC"]];
int AT = pref_typ[k+1][typ["AT"]] - pref_typ[p][typ["AT"]];
int CA = pref_typ[k+1][typ["CA"]] - pref_typ[p][typ["CA"]];
int CT = pref_typ[k+1][typ["CT"]] - pref_typ[p][typ["CT"]];
int TC = pref_typ[k+1][typ["TC"]] - pref_typ[p][typ["TC"]];
int TA = pref_typ[k+1][typ["TA"]] - pref_typ[p][typ["TA"]];
//dwa
ust -= min(AC,CA)*2;
ans += min(AC,CA);
ust -= min(AT,TA)*2;
ans += min(AT,TA);
ust -= min(CA,AC)*2;
ans += min(CA,AC);
ust -= min(CT,TC)*2;
ans += min(CT,TC);
ust -= min(TA,AT)*2;
ans += min(TA,AT);
ust -= min(TC,CT)*2;
ans += min(TC,CT);
//trzy
return ans+max(0,ust-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... |