제출 #828474

#제출 시각아이디문제언어결과실행 시간메모리
828474TheSahibDNA 돌연변이 (IOI21_dna)C++17
100 / 100
31 ms7420 KiB
#pragma GCC optimize("O3")
#include "dna.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX = 1e5 + 5;

int n;
int pre[MAX][3][3];

map<char, int> mp = {{'A', 0}, {'C', 1}, {'T', 2}};

void init(string a, string b) {
	n = a.size();
	for (int i = 0; i < n; i++)
	{
		pre[i + 1][mp[a[i]]][mp[b[i]]]++;
	}
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 3; k++)
			{
				pre[i][j][k] += pre[i - 1][j][k];
			}
		}
	}
}

int get_distance(int x, int y) {
	y += 1;
	int arr[3][3];
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			arr[i][j] = pre[y][i][j] - pre[x][i][j];
		}
	}
	for (int i = 0; i < 3; i++)
	{
		int s1 = 0, s2 = 0;
		s1 += arr[i][0] + arr[i][1] + arr[i][2];
		s2 += arr[0][i] + arr[1][i] + arr[2][i];
		if(s1 != s2){
			return -1;
		}
	}
	int s = 0, ans = 0;
	for (int i = 0; i < 3; i++)
	{
		for (int j = i + 1; j < 3; j++)
		{
			if(arr[i][j] < arr[j][i]) swap(arr[i][j], arr[j][i]);
			ans += arr[j][i];
			s += arr[i][j] - arr[j][i];
		}
	}
	ans += s / 3 * 2;
	return ans;
}
#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...