이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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"]];
int pom;
//dwa
ust -= min(AC,CA)*2;
ans += min(AC,CA);
pom = min(AC,CA);
AC -= pom;
CA -= pom;
ust -= min(AT,TA)*2;
ans += min(AT,TA);
pom = min(TA,AT);
TA -= pom;
AT -= pom;
ust -= min(TC,CT)*2;
ans += min(TC,CT);
pom = min(TC,CT);
TC -= pom;
CT -= pom;
//trzy
ust -= min(min(AT,TC),CA)*3;
ans += min(min(AT,TC),CA)*2;
pom = min(min(AT,TC),CA);
AT -= pom;
TC -= pom;
CA -= pom;
ust -= min(min(AC,CT),TA)*3;
ans += min(min(AC,CT),TA)*2;
pom = min(min(AC,CT),TA);
AC -= pom;
CT -= pom;
TA -= pom;
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... |