# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1106634 |
2024-10-30T18:11:06 Z |
kheira |
Mutating DNA (IOI21_dna) |
C++17 |
|
39 ms |
8708 KB |
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> A_a, C_a, T_a;
vector<int> A_b, C_b, T_b;
vector<int> AC_ab, AT_ab, CA_ab, CT_ab, TA_ab, TC_ab;
string aa, bb;
void init(string a, string b) {
int n = a.size();
A_a = C_a = T_a = vector<int>(n + 1, 0);
A_b = C_b = T_b = vector<int>(n + 1, 0);
AC_ab = AT_ab = CA_ab = CT_ab = TA_ab = TC_ab = vector<int>(n + 1, 0);
for (int i = 1; i <= n; ++i) {
A_a[i] = A_a[i - 1] + (a[i - 1] == 'A');
C_a[i] = C_a[i - 1] + (a[i - 1] == 'C');
T_a[i] = T_a[i - 1] + (a[i - 1] == 'T');
A_b[i] = A_b[i - 1] + (b[i - 1] == 'A');
C_b[i] = C_b[i - 1] + (b[i - 1] == 'C');
T_b[i] = T_b[i - 1] + (b[i - 1] == 'T');
if (a[i - 1] == 'A' && b[i - 1] == 'C') AC_ab[i]++;
if (a[i - 1] == 'A' && b[i - 1] == 'T') AT_ab[i]++;
if (a[i - 1] == 'C' && b[i - 1] == 'A') CA_ab[i]++;
if (a[i - 1] == 'C' && b[i - 1] == 'T') CT_ab[i]++;
if (a[i - 1] == 'T' && b[i - 1] == 'A') TA_ab[i]++;
if (a[i - 1] == 'T' && b[i - 1] == 'C') TC_ab[i]++;
AC_ab[i] += AC_ab[i - 1];
AT_ab[i] += AT_ab[i - 1];
CA_ab[i] += CA_ab[i - 1];
CT_ab[i] += CT_ab[i - 1];
TA_ab[i] += TA_ab[i - 1];
TC_ab[i] += TC_ab[i - 1];
}
}
int get_distance(int x, int y) {
int a_count_A = A_a[y + 1] - A_a[x];
int a_count_C = C_a[y + 1] - C_a[x];
int a_count_T = T_a[y + 1] - T_a[x];
int b_count_A = A_b[y + 1] - A_b[x];
int b_count_C = C_b[y + 1] - C_b[x];
int b_count_T = T_b[y + 1] - T_b[x];
if (a_count_A != b_count_A || a_count_C != b_count_C || a_count_T != b_count_T) {
return -1;
}
int min_AT = min(AT_ab[y + 1] - AT_ab[x], TA_ab[y + 1] - TA_ab[x]);
int min_AC = min(AC_ab[y + 1] - AC_ab[x], CA_ab[y + 1] - CA_ab[x]);
int min_CT = min(CT_ab[y + 1] - CT_ab[x], TC_ab[y + 1] - TC_ab[x]);
int total_makanch = min_AT + min_AC + min_CT;
int remaining_makanch = (max(AT_ab[y + 1] - AT_ab[x], TA_ab[y + 1] - TA_ab[x]) -
min(AT_ab[y + 1] - AT_ab[x], TA_ab[y + 1] - TA_ab[x])) * 2;
return total_makanch + remaining_makanch;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
6920 KB |
Output is correct |
2 |
Correct |
30 ms |
8204 KB |
Output is correct |
3 |
Correct |
29 ms |
7760 KB |
Output is correct |
4 |
Correct |
30 ms |
8372 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
13 ms |
5888 KB |
Output is correct |
5 |
Correct |
12 ms |
5712 KB |
Output is correct |
6 |
Correct |
12 ms |
6032 KB |
Output is correct |
7 |
Correct |
11 ms |
5544 KB |
Output is correct |
8 |
Correct |
11 ms |
5948 KB |
Output is correct |
9 |
Correct |
12 ms |
5884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
13 ms |
5888 KB |
Output is correct |
5 |
Correct |
12 ms |
5712 KB |
Output is correct |
6 |
Correct |
12 ms |
6032 KB |
Output is correct |
7 |
Correct |
11 ms |
5544 KB |
Output is correct |
8 |
Correct |
11 ms |
5948 KB |
Output is correct |
9 |
Correct |
12 ms |
5884 KB |
Output is correct |
10 |
Correct |
32 ms |
8280 KB |
Output is correct |
11 |
Correct |
31 ms |
8188 KB |
Output is correct |
12 |
Correct |
32 ms |
8220 KB |
Output is correct |
13 |
Correct |
35 ms |
8312 KB |
Output is correct |
14 |
Correct |
39 ms |
8688 KB |
Output is correct |
15 |
Correct |
36 ms |
8452 KB |
Output is correct |
16 |
Correct |
33 ms |
8144 KB |
Output is correct |
17 |
Correct |
35 ms |
8212 KB |
Output is correct |
18 |
Correct |
32 ms |
8452 KB |
Output is correct |
19 |
Correct |
33 ms |
8220 KB |
Output is correct |
20 |
Correct |
33 ms |
8364 KB |
Output is correct |
21 |
Correct |
38 ms |
8452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
13 ms |
5888 KB |
Output is correct |
5 |
Correct |
12 ms |
5712 KB |
Output is correct |
6 |
Correct |
12 ms |
6032 KB |
Output is correct |
7 |
Correct |
11 ms |
5544 KB |
Output is correct |
8 |
Correct |
11 ms |
5948 KB |
Output is correct |
9 |
Correct |
12 ms |
5884 KB |
Output is correct |
10 |
Correct |
11 ms |
5456 KB |
Output is correct |
11 |
Correct |
11 ms |
5940 KB |
Output is correct |
12 |
Correct |
11 ms |
5456 KB |
Output is correct |
13 |
Correct |
12 ms |
5712 KB |
Output is correct |
14 |
Correct |
12 ms |
5712 KB |
Output is correct |
15 |
Correct |
14 ms |
5940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
6920 KB |
Output is correct |
2 |
Correct |
30 ms |
8204 KB |
Output is correct |
3 |
Correct |
29 ms |
7760 KB |
Output is correct |
4 |
Correct |
30 ms |
8372 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
504 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
504 KB |
Output is correct |
11 |
Correct |
13 ms |
5888 KB |
Output is correct |
12 |
Correct |
12 ms |
5712 KB |
Output is correct |
13 |
Correct |
12 ms |
6032 KB |
Output is correct |
14 |
Correct |
11 ms |
5544 KB |
Output is correct |
15 |
Correct |
11 ms |
5948 KB |
Output is correct |
16 |
Correct |
12 ms |
5884 KB |
Output is correct |
17 |
Correct |
32 ms |
8280 KB |
Output is correct |
18 |
Correct |
31 ms |
8188 KB |
Output is correct |
19 |
Correct |
32 ms |
8220 KB |
Output is correct |
20 |
Correct |
35 ms |
8312 KB |
Output is correct |
21 |
Correct |
39 ms |
8688 KB |
Output is correct |
22 |
Correct |
36 ms |
8452 KB |
Output is correct |
23 |
Correct |
33 ms |
8144 KB |
Output is correct |
24 |
Correct |
35 ms |
8212 KB |
Output is correct |
25 |
Correct |
32 ms |
8452 KB |
Output is correct |
26 |
Correct |
33 ms |
8220 KB |
Output is correct |
27 |
Correct |
33 ms |
8364 KB |
Output is correct |
28 |
Correct |
38 ms |
8452 KB |
Output is correct |
29 |
Correct |
11 ms |
5456 KB |
Output is correct |
30 |
Correct |
11 ms |
5940 KB |
Output is correct |
31 |
Correct |
11 ms |
5456 KB |
Output is correct |
32 |
Correct |
12 ms |
5712 KB |
Output is correct |
33 |
Correct |
12 ms |
5712 KB |
Output is correct |
34 |
Correct |
14 ms |
5940 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
36 ms |
7768 KB |
Output is correct |
37 |
Correct |
32 ms |
8204 KB |
Output is correct |
38 |
Correct |
35 ms |
8212 KB |
Output is correct |
39 |
Correct |
33 ms |
8692 KB |
Output is correct |
40 |
Correct |
39 ms |
8708 KB |
Output is correct |
41 |
Correct |
11 ms |
5712 KB |
Output is correct |
42 |
Correct |
32 ms |
8088 KB |
Output is correct |
43 |
Correct |
35 ms |
8452 KB |
Output is correct |
44 |
Correct |
36 ms |
8452 KB |
Output is correct |
45 |
Correct |
32 ms |
8164 KB |
Output is correct |
46 |
Correct |
31 ms |
8460 KB |
Output is correct |
47 |
Correct |
31 ms |
8460 KB |
Output is correct |