Submission #1010476

# Submission time Handle Problem Language Result Execution time Memory
1010476 2024-06-29T06:42:01 Z induwara16 Mutating DNA (IOI21_dna) C++17
100 / 100
30 ms 8916 KB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;

typedef string str;
typedef vector<int> vi;

str a, b;
vi ac, at, ca, ct, ta, tc, as1, cs1, ts1, as2, cs2, ts2;

void init(str a1, str b1)
{
	a = a1;
	b = b1;

	int n = a.length();

	ac = vi(n);
	at = vi(n);
	ca = vi(n);
	at = vi(n);
	ta = vi(n);
	tc = vi(n);
	ct = vi(n);
	as1 = vi(n);
	cs1 = vi(n);
	ts1 = vi(n);
	as2 = vi(n);
	cs2 = vi(n);
	ts2 = vi(n);

	int ac_ = 0,
		at_ = 0,
		ca_ = 0,
		ta_ = 0,
		tc_ = 0,
		ct_ = 0,
		as1_ = 0,
		cs1_ = 0,
		ts1_ = 0,
		as2_ = 0,
		cs2_ = 0,
		ts2_ = 0;

	for (int i = 0; i < n; i++)
	{
		switch (b[i])
		{
		case 'A':
			as2_++;
			as2[i] = as2_;
			cs2[i] = cs2_;
			ts2[i] = ts2_;
			break;
		case 'C':
			cs2_++;
			as2[i] = as2_;
			cs2[i] = cs2_;
			ts2[i] = ts2_;
			break;
		case 'T':
			ts2_++;
			as2[i] = as2_;
			cs2[i] = cs2_;
			ts2[i] = ts2_;
			break;
		}
		switch (a[i])
		{
		case 'A':
			as1_++;
			as1[i] = as1_;
			cs1[i] = cs1_;
			ts1[i] = ts1_;

			if (b[i] == 'C')
				ac_++;
			else if (b[i] == 'T')
				at_++;

			ac[i] = ac_;
			at[i] = at_;
			ca[i] = ca_;
			ct[i] = ct_;
			tc[i] = tc_;
			ta[i] = ta_;
			break;
		case 'C':
			cs1_++;
			as1[i] = as1_;
			cs1[i] = cs1_;
			ts1[i] = ts1_;

			if (b[i] == 'A')
				ca_++;
			else if (b[i] == 'T')
				ct_++;

			ac[i] = ac_;
			at[i] = at_;
			ca[i] = ca_;
			ct[i] = ct_;
			tc[i] = tc_;
			ta[i] = ta_;
			break;
		case 'T':
			ts1_++;
			as1[i] = as1_;
			cs1[i] = cs1_;
			ts1[i] = ts1_;

			if (b[i] == 'C')
				tc_++;
			else if (b[i] == 'A')
				ta_++;

			ac[i] = ac_;
			at[i] = at_;
			ca[i] = ca_;
			ct[i] = ct_;
			tc[i] = tc_;
			ta[i] = ta_;

			break;
		}
	}
}

int get_distance(int x, int y)
{
	if (
		(as1[y] - (x == 0 ? 0 : as1[x - 1])) != (as2[y] - (x == 0 ? 0 : as2[x - 1])) ||
		(cs1[y] - (x == 0 ? 0 : cs1[x - 1])) != (cs2[y] - (x == 0 ? 0 : cs2[x - 1])) ||
		(ts1[y] - (x == 0 ? 0 : ts1[x - 1])) != (ts2[y] - (x == 0 ? 0 : ts2[x - 1])))
		return -1;

	int cntAC = ac[y] - (x == 0 ? 0 : ac[x - 1]);
	int cntAT = at[y] - (x == 0 ? 0 : at[x - 1]);
	int cntCA = ca[y] - (x == 0 ? 0 : ca[x - 1]);
	int cntCT = ct[y] - (x == 0 ? 0 : ct[x - 1]);
	int cntTA = ta[y] - (x == 0 ? 0 : ta[x - 1]);
	int cntTC = tc[y] - (x == 0 ? 0 : tc[x - 1]);

	int c = 0, m = cntAC + cntCA + cntAT + cntTA + cntTC + cntCT;

	m -= min(cntAC, cntCA) * 2;
	c += min(cntAC, cntCA);

	m -= min(cntAT, cntTA) * 2;
	c += min(cntAT, cntTA);

	m -= min(cntTC, cntCT) * 2;
	c += min(cntTC, cntCT);

	return m / 3 * 2 + c;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 8148 KB Output is correct
2 Correct 25 ms 8148 KB Output is correct
3 Correct 23 ms 7660 KB Output is correct
4 Correct 30 ms 8520 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 4 ms 5976 KB Output is correct
5 Correct 4 ms 6100 KB Output is correct
6 Correct 4 ms 5944 KB Output is correct
7 Correct 5 ms 5616 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 4 ms 5976 KB Output is correct
5 Correct 4 ms 6100 KB Output is correct
6 Correct 4 ms 5944 KB Output is correct
7 Correct 5 ms 5616 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6096 KB Output is correct
10 Correct 21 ms 8064 KB Output is correct
11 Correct 19 ms 8404 KB Output is correct
12 Correct 24 ms 8168 KB Output is correct
13 Correct 24 ms 8412 KB Output is correct
14 Correct 25 ms 8636 KB Output is correct
15 Correct 23 ms 8396 KB Output is correct
16 Correct 23 ms 7984 KB Output is correct
17 Correct 23 ms 8160 KB Output is correct
18 Correct 23 ms 8396 KB Output is correct
19 Correct 21 ms 7912 KB Output is correct
20 Correct 22 ms 8160 KB Output is correct
21 Correct 22 ms 8396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 4 ms 5976 KB Output is correct
5 Correct 4 ms 6100 KB Output is correct
6 Correct 4 ms 5944 KB Output is correct
7 Correct 5 ms 5616 KB Output is correct
8 Correct 4 ms 6100 KB Output is correct
9 Correct 4 ms 6096 KB Output is correct
10 Correct 5 ms 5616 KB Output is correct
11 Correct 4 ms 6100 KB Output is correct
12 Correct 4 ms 5768 KB Output is correct
13 Correct 5 ms 5976 KB Output is correct
14 Correct 5 ms 6100 KB Output is correct
15 Correct 4 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 8148 KB Output is correct
2 Correct 25 ms 8148 KB Output is correct
3 Correct 23 ms 7660 KB Output is correct
4 Correct 30 ms 8520 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 4 ms 5976 KB Output is correct
12 Correct 4 ms 6100 KB Output is correct
13 Correct 4 ms 5944 KB Output is correct
14 Correct 5 ms 5616 KB Output is correct
15 Correct 4 ms 6100 KB Output is correct
16 Correct 4 ms 6096 KB Output is correct
17 Correct 21 ms 8064 KB Output is correct
18 Correct 19 ms 8404 KB Output is correct
19 Correct 24 ms 8168 KB Output is correct
20 Correct 24 ms 8412 KB Output is correct
21 Correct 25 ms 8636 KB Output is correct
22 Correct 23 ms 8396 KB Output is correct
23 Correct 23 ms 7984 KB Output is correct
24 Correct 23 ms 8160 KB Output is correct
25 Correct 23 ms 8396 KB Output is correct
26 Correct 21 ms 7912 KB Output is correct
27 Correct 22 ms 8160 KB Output is correct
28 Correct 22 ms 8396 KB Output is correct
29 Correct 5 ms 5616 KB Output is correct
30 Correct 4 ms 6100 KB Output is correct
31 Correct 4 ms 5768 KB Output is correct
32 Correct 5 ms 5976 KB Output is correct
33 Correct 5 ms 6100 KB Output is correct
34 Correct 4 ms 6100 KB Output is correct
35 Correct 1 ms 432 KB Output is correct
36 Correct 25 ms 8044 KB Output is correct
37 Correct 23 ms 8472 KB Output is correct
38 Correct 25 ms 8424 KB Output is correct
39 Correct 25 ms 8916 KB Output is correct
40 Correct 25 ms 8772 KB Output is correct
41 Correct 4 ms 6096 KB Output is correct
42 Correct 20 ms 8484 KB Output is correct
43 Correct 23 ms 8916 KB Output is correct
44 Correct 22 ms 8904 KB Output is correct
45 Correct 29 ms 8416 KB Output is correct
46 Correct 24 ms 8904 KB Output is correct
47 Correct 29 ms 8904 KB Output is correct