#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
string aa, bb;
int n = 100010;
vector< vector<int> >pref(10, vector<int>(n, 0));
void init(std::string a, std::string b) {
aa=a;
bb=b;
n = a.length();
/*
0 uk
1 AT
2 TA
3 AC
4 CA
5 TC
6 CT
TAC
CTA
*/
for(int i = 0; i<=6; i++)
{
for(int j = 0; j<n; j++)
{
pref[i][j]=pref[i][max(0, j-1)];
if(i==0 && a[j]!=b[j])pref[i][j]++;
else if(i==1 && a[j]=='A' && b[j]=='T')pref[i][j]++;
else if(i==2 && a[j]=='T' && b[j]=='A')pref[i][j]++;
else if(i==3 && a[j]=='A' && b[j]=='C')pref[i][j]++;
else if(i==4 && a[j]=='C' && b[j]=='A')pref[i][j]++;
else if(i==5 && a[j]=='T' && b[j]=='C')pref[i][j]++;
else if(i==6 && a[j]=='C' && b[j]=='T')pref[i][j]++;
}
}
}
int get_distance(int x, int y)
{
map<char, int>m1, m2;
for(int i = x; i<=y; i++)
{
m1[aa[i]]++;
m2[bb[i]]++;
}
if(m1['A']!=m2['A'] || m1['T']!=m2['T'] || m1['C']!=m2['C'])
{
return -1;
}
int a=0;
if(x>0)a=x-1;
int cnt = 0;
cnt += min(pref[1][y]-pref[1][a], pref[2][y]-pref[2][a]);
cnt += min(pref[3][y]-pref[3][a], pref[4][y]-pref[4][a]);
cnt+= min(pref[5][y]-pref[5][a], pref[6][y]-pref[6][a]);
int uk = pref[0][y]-pref[0][a];
int ans = cnt + 2*(uk - 2*cnt)/3;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
6536 KB |
Output is correct |
2 |
Correct |
47 ms |
7036 KB |
Output is correct |
3 |
Correct |
49 ms |
6856 KB |
Output is correct |
4 |
Correct |
48 ms |
7108 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4700 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4700 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4700 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4700 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
6536 KB |
Output is correct |
2 |
Correct |
47 ms |
7036 KB |
Output is correct |
3 |
Correct |
49 ms |
6856 KB |
Output is correct |
4 |
Correct |
48 ms |
7108 KB |
Output is correct |
5 |
Correct |
2 ms |
4700 KB |
Output is correct |
6 |
Incorrect |
3 ms |
4700 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |