제출 #936115

#제출 시각아이디문제언어결과실행 시간메모리
936115AtabayRajabliDNA 돌연변이 (IOI21_dna)C++17
100 / 100
37 ms8372 KiB
#include <bits/stdc++.h>
#include "dna.h"

using namespace std;

int n;
int p[7][1000005];
int af[4][100005], bf[4][100005];
string ax = " ACATCT";
string bx = " CATATC";
string f = " ACT";

void init(string a, string b) 
{
	n = a.size();
	a = ' ' + a;
	b = ' ' + b;
	
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= 6; j++)
		{
			if(a[i] == ax[j] && b[i] == bx[j])p[j][i]++;
			p[j][i] += p[j][i - 1];
		}
		for(int j = 1; j <= 3; j++)
		{
			af[j][i] = af[j][i - 1] + (f[j] == a[i]);
			bf[j][i] = bf[j][i - 1] + (f[j] == b[i]);
		}
	}
}

int get_distance(int x, int y)
{
	++x, ++y;
	for(int i = 1; i <= 3; i++)
	{
		if(af[i][y] - af[i][x - 1] != bf[i][y] - bf[i][x - 1])return -1;
	}
	int s[7] = {0};
	for(int i = 1; i <= 6; i++)
	{
		s[i] = p[i][y] - p[i][x - 1];
	}

	int ans = 0;
	int sx[4] = {0}, j = 1;
	for(int i = 1; i < 6; i += 2, j++)
	{
		ans += min(s[i], s[i + 1]);
		sx[j] += max(s[i], s[i + 1]) - min(s[i], s[i + 1]);
	}
	sort(sx + 1, sx + 1 + 3);

	return ans + sx[1] + sx[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...