#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int asum[100050][3], bsum[100050][3];
int cnt[100050][3][3];
void init(std::string a, std::string b){
n = (int)a.size();
for(int i = 0; i < n; i++){
if(a[i] == 'A') asum[i + 1][0] ++;
else if(a[i] == 'C') asum[i + 1][1] ++;
else asum[i + 1][2]++;
if(b[i] == 'A') bsum[i + 1][0] ++;
else if(b[i] == 'C') bsum[i + 1][1] ++;
else bsum[i + 1][2]++;
}
for(int i = 2; i <= n; i++){
for(int j = 0; j < 3; j++){
asum[i][j] += asum[i - 1][j];
bsum[i][j] += bsum[i - 1][j];
}
}
for(int i = 0; i < n; i++){
int ai = 2, bi = 2;
if(a[i] == 'A') ai = 0;
else if(a[i] == 'C') ai = 1;
if(b[i] == 'A') bi = 0;
else if(b[i] == 'C') bi = 1;
cnt[i + 1][ai][bi] = 1;
}
for(int i = 2; i <= n; i++){
for(int j = 0; j < 3; j++){
for(int jj = 0; jj < 3; jj++){
cnt[i][j][jj] += cnt[i - 1][j][jj];
}
}
}
}
int get_distance(int x, int y){
x++, y++;
for(int j = 0; j < 3; j++){
if(asum[y][j] - asum[x - 1][j] != bsum[y][j] - bsum[x - 1][j]){
return -1;
}
}
int ac = cnt[y][0][1] - cnt[x - 1][0][1];
int ca = cnt[y][1][0] - cnt[x - 1][1][0];
int at = cnt[y][0][2] - cnt[x - 1][0][2];
int ta = cnt[y][2][0] - cnt[x - 1][2][0];
int tc = cnt[y][2][1] - cnt[x - 1][2][1];
int ct = cnt[y][1][2] - cnt[x - 1][1][2];
int ans = (min(ac, ca) + min(at, ta) + min(tc, ct) + 1) / 2 + (abs(ac - ca) + abs(ta - at) + abs(ct - tc)) / 3 * 2;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8260 KB |
Output is correct |
2 |
Correct |
27 ms |
8976 KB |
Output is correct |
3 |
Correct |
26 ms |
8484 KB |
Output is correct |
4 |
Correct |
26 ms |
8716 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2496 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
6748 KB |
Output is correct |
5 |
Correct |
5 ms |
6748 KB |
Output is correct |
6 |
Incorrect |
4 ms |
6748 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
6748 KB |
Output is correct |
5 |
Correct |
5 ms |
6748 KB |
Output is correct |
6 |
Incorrect |
4 ms |
6748 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
6748 KB |
Output is correct |
5 |
Correct |
5 ms |
6748 KB |
Output is correct |
6 |
Incorrect |
4 ms |
6748 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8260 KB |
Output is correct |
2 |
Correct |
27 ms |
8976 KB |
Output is correct |
3 |
Correct |
26 ms |
8484 KB |
Output is correct |
4 |
Correct |
26 ms |
8716 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2496 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
5 ms |
6748 KB |
Output is correct |
12 |
Correct |
5 ms |
6748 KB |
Output is correct |
13 |
Incorrect |
4 ms |
6748 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |