Submission #832344

#TimeUsernameProblemLanguageResultExecution timeMemory
832344Pablo_NoMutating DNA (IOI21_dna)C++17
0 / 100
25 ms5652 KiB
#include "dna.h"

#include <algorithm>
#include <iostream>

using namespace std;

const int N = 1e5+5;

int p[3][3][N];

int GN;

void init(std::string a, std::string b) {
	GN = a.length();

	for(char& c : a)
	{
		if(c == 'T')
			c = 'B';
	}

	for(char& c : b)
	{
		if(c == 'T')
			c = 'B';
	}

	for(int i = 0; i < GN; i++)
	{
		int c1 = a[i]-'A';
		int c2 = b[i]-'A';

		for(int k1 = 0; k1 < 3; k1++)
			for(int k2 = 0; k2 < 3; k2++)
			{
				p[k1][k2][i+1] = p[k1][k2][i] + (c1 == k1)*(c2 == k2);
			}
	}

}

int get_distance(int x, int y) {
	x++, y++;

	int ab, bc, ca, ba, ac, cb;

	ab = p[0][1][y]-p[0][1][x-1];
	bc = p[1][2][y]-p[1][2][x-1];
	ca = p[2][0][y]-p[2][0][x-1];
	ba = p[1][0][y]-p[1][0][x-1];
	ac = p[0][2][y]-p[0][2][x-1];
	cb = p[2][1][y]-p[2][1][x-1];

	//cerr << ab << bc << ca << ba << ac << cb << '\n';

	if(ab+ac != ba+ca ||
	   bc+ba != ab+cb ||
	   ca+cb != ac+bc)
	   return -1;

	int tt = min(ab, ba)+min(bc, cb)+min(ca, ac);
	
	return tt+(y-x+1-tt*2)*2/3;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...