#include "dna.h"
#include <string>
#include <cstdlib>
using namespace std;
int A[2][100005], C[2][100005], AC[100005], same[100005];
void init(string a, string b) {
int n = a.length();
for (int i = 0; i < n; i++) {
A[0][i + 1] = A[0][i];
A[1][i + 1] = A[1][i];
C[0][i + 1] = C[0][i];
C[1][i + 1] = C[1][i];
AC[i + 1] = AC[i];
same[i + 1] = same[i];
if (a[i] == 'A')
A[0][i + 1]++;
if (b[i] == 'A')
A[1][i + 1]++;
if (a[i] == 'C')
C[0][i + 1]++;
if (b[i] == 'C')
C[1][i + 1]++;
if (a[i] == 'A' && b[i] == 'C')
AC[i + 1]++;
if (a[i] == 'C' && b[i] == 'A')
AC[i + 1]--;
if (a[i] == b[i])
same[i + 1]++;
}
}
int get_distance(int x, int y) {
if ((A[0][y + 1] - A[0][x] != A[1][y + 1] - A[1][x]) || (C[0][y + 1] - C[0][x] != C[1][y + 1] - C[1][x]))
return -1;
return ((y - x + 1) - (same[y + 1] - same[x]) + abs(AC[y + 1] - AC[x])) / 2;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
4484 KB |
Output is correct |
2 |
Correct |
36 ms |
4472 KB |
Output is correct |
3 |
Correct |
36 ms |
4188 KB |
Output is correct |
4 |
Correct |
40 ms |
4452 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
3148 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3156 KB |
Output is correct |
7 |
Correct |
4 ms |
3020 KB |
Output is correct |
8 |
Correct |
4 ms |
3148 KB |
Output is correct |
9 |
Correct |
3 ms |
3148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
3148 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3156 KB |
Output is correct |
7 |
Correct |
4 ms |
3020 KB |
Output is correct |
8 |
Correct |
4 ms |
3148 KB |
Output is correct |
9 |
Correct |
3 ms |
3148 KB |
Output is correct |
10 |
Correct |
38 ms |
4464 KB |
Output is correct |
11 |
Correct |
36 ms |
4452 KB |
Output is correct |
12 |
Correct |
38 ms |
4672 KB |
Output is correct |
13 |
Correct |
36 ms |
4676 KB |
Output is correct |
14 |
Correct |
37 ms |
4856 KB |
Output is correct |
15 |
Correct |
34 ms |
4708 KB |
Output is correct |
16 |
Correct |
35 ms |
4624 KB |
Output is correct |
17 |
Correct |
35 ms |
4724 KB |
Output is correct |
18 |
Correct |
34 ms |
4836 KB |
Output is correct |
19 |
Correct |
34 ms |
4628 KB |
Output is correct |
20 |
Correct |
32 ms |
4748 KB |
Output is correct |
21 |
Correct |
33 ms |
4852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
4 ms |
3148 KB |
Output is correct |
5 |
Correct |
4 ms |
3156 KB |
Output is correct |
6 |
Correct |
4 ms |
3156 KB |
Output is correct |
7 |
Correct |
4 ms |
3020 KB |
Output is correct |
8 |
Correct |
4 ms |
3148 KB |
Output is correct |
9 |
Correct |
3 ms |
3148 KB |
Output is correct |
10 |
Correct |
5 ms |
2892 KB |
Output is correct |
11 |
Correct |
4 ms |
3148 KB |
Output is correct |
12 |
Correct |
4 ms |
3020 KB |
Output is correct |
13 |
Correct |
4 ms |
3148 KB |
Output is correct |
14 |
Correct |
4 ms |
3148 KB |
Output is correct |
15 |
Correct |
3 ms |
3148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
4484 KB |
Output is correct |
2 |
Correct |
36 ms |
4472 KB |
Output is correct |
3 |
Correct |
36 ms |
4188 KB |
Output is correct |
4 |
Correct |
40 ms |
4452 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
4 ms |
3148 KB |
Output is correct |
12 |
Correct |
4 ms |
3156 KB |
Output is correct |
13 |
Correct |
4 ms |
3156 KB |
Output is correct |
14 |
Correct |
4 ms |
3020 KB |
Output is correct |
15 |
Correct |
4 ms |
3148 KB |
Output is correct |
16 |
Correct |
3 ms |
3148 KB |
Output is correct |
17 |
Correct |
38 ms |
4464 KB |
Output is correct |
18 |
Correct |
36 ms |
4452 KB |
Output is correct |
19 |
Correct |
38 ms |
4672 KB |
Output is correct |
20 |
Correct |
36 ms |
4676 KB |
Output is correct |
21 |
Correct |
37 ms |
4856 KB |
Output is correct |
22 |
Correct |
34 ms |
4708 KB |
Output is correct |
23 |
Correct |
35 ms |
4624 KB |
Output is correct |
24 |
Correct |
35 ms |
4724 KB |
Output is correct |
25 |
Correct |
34 ms |
4836 KB |
Output is correct |
26 |
Correct |
34 ms |
4628 KB |
Output is correct |
27 |
Correct |
32 ms |
4748 KB |
Output is correct |
28 |
Correct |
33 ms |
4852 KB |
Output is correct |
29 |
Correct |
5 ms |
2892 KB |
Output is correct |
30 |
Correct |
4 ms |
3148 KB |
Output is correct |
31 |
Correct |
4 ms |
3020 KB |
Output is correct |
32 |
Correct |
4 ms |
3148 KB |
Output is correct |
33 |
Correct |
4 ms |
3148 KB |
Output is correct |
34 |
Correct |
3 ms |
3148 KB |
Output is correct |
35 |
Correct |
0 ms |
204 KB |
Output is correct |
36 |
Correct |
36 ms |
4232 KB |
Output is correct |
37 |
Correct |
37 ms |
4400 KB |
Output is correct |
38 |
Correct |
36 ms |
4712 KB |
Output is correct |
39 |
Correct |
37 ms |
4772 KB |
Output is correct |
40 |
Correct |
36 ms |
4856 KB |
Output is correct |
41 |
Correct |
4 ms |
3148 KB |
Output is correct |
42 |
Correct |
36 ms |
4628 KB |
Output is correct |
43 |
Correct |
34 ms |
4872 KB |
Output is correct |
44 |
Correct |
34 ms |
4864 KB |
Output is correct |
45 |
Correct |
32 ms |
4720 KB |
Output is correct |
46 |
Correct |
33 ms |
4848 KB |
Output is correct |
47 |
Correct |
34 ms |
4912 KB |
Output is correct |