제출 #1091574

#제출 시각아이디문제언어결과실행 시간메모리
1091574owieczkaMutating DNA (IOI21_dna)C++17
100 / 100
28 ms6696 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;

int ps[7][100'004];
int n;

void init(std::string a, std::string b) {
	n = a.size();
	for (int i = 0; i < n; i++)
	{
		int x = 6;
		if(a[i] == 'A' && b[i] == 'T')
		{
			x = 0;
		}
		else if (a[i] == 'A' && b[i] == 'C')
		{
			x = 1;
		}
		else if (a[i] == 'T' && b[i] == 'A')
		{
			x = 2;
		}
		else if (a[i] == 'T' && b[i] == 'C')
		{
			x = 3;
		}
		else if (a[i] == 'C' && b[i] == 'A')
		{
			x = 4;
		}
		else if (a[i] == 'C' && b[i] == 'T')
		{
			x = 5;
		}
		ps[x][i+1] = 1;
		// if (!i)continue;
		for (int j = 0; j < 7; j++)
		{
			ps[j][i+1] += ps[j][i];
		}
	}
}

int get_distance(int x, int y) {
	int w = 0;
	x++; y++;
	int t[9];
	for (int i = 0; i < 6; i++)
	{
		t[i] = ps[i][y] - ps[i][x-1];
	}
	if (t[0]+t[1] != t[2]+t[4])return -1;
	if (t[2]+t[3] != t[0]+t[5])return -1;
	if (t[4]+t[5] != t[1]+t[3])return -1;

	w += min(t[0], t[2]);
	w += min(t[1], t[4]);
	w += min(t[3], t[5]);
	if (t[0] > t[2])
	{
		t[0] -= t[2];
		t[2] = 0;
	}
	else 
	{
		t[2] -= t[0];
		t[0] = 0;
	}

	if (t[1] > t[4])
	{
		t[1] -= t[4];
		t[4] = 0;
	}
	else 
	{
		t[4] -= t[1];
		t[1] = 0;
	}
	
	if (t[3] > t[5])
	{
		t[3] -= t[5];
		t[5] = 0;
	}
	else 
	{
		t[5] -= t[3];
		t[3] = 0;
	}
	w += t[0] + t[1] + t[2] + t[4];
	return w;
	
}
#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...