Submission #568187

#TimeUsernameProblemLanguageResultExecution timeMemory
568187d4xnDNA 돌연변이 (IOI21_dna)C++17
56 / 100
40 ms7648 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+5;

int pa[2][N];
int pt[2][N];
int pc[2][N];
int pma[2][N];
int pmt[2][N];
int pmc[2][N];
int pdif[N];

void init(std::string a, std::string b) {
	int n = min(a.size(), b.size());
	for (int i = 0; i < n; i++) {
		pa[0][i] = (i == 0 ? 0 : pa[0][i-1]);
		pt[0][i] = (i == 0 ? 0 : pt[0][i-1]);
		pc[0][i] = (i == 0 ? 0 : pc[0][i-1]);

		pa[1][i] = (i == 0 ? 0 : pa[1][i-1]);
		pt[1][i] = (i == 0 ? 0 : pt[1][i-1]);
		pc[1][i] = (i == 0 ? 0 : pc[1][i-1]);

		pma[0][i] = (i == 0 ? 0 : pma[0][i-1]);
		pmt[0][i] = (i == 0 ? 0 : pmt[0][i-1]);
		pmc[0][i] = (i == 0 ? 0 : pmc[0][i-1]);

		pma[1][i] = (i == 0 ? 0 : pma[1][i-1]);
		pmt[1][i] = (i == 0 ? 0 : pmt[1][i-1]);
		pmc[1][i] = (i == 0 ? 0 : pmc[1][i-1]);

		pdif[i] = (i == 0 ? 0 : pdif[i-1]);

		if (a[i] == 'A') pa[0][i]++;
		if (a[i] == 'T') pt[0][i]++;
		if (a[i] == 'C') pc[0][i]++;

		if (b[i] == 'A') pa[1][i]++;
		if (b[i] == 'T') pt[1][i]++;
		if (b[i] == 'C') pc[1][i]++;

		if (a[i] != b[i]) {
			pdif[i]++;

			if (a[i] == 'A') pma[0][i]++;
			if (a[i] == 'T') pmt[0][i]++;
			if (a[i] == 'C') pmc[0][i]++;

			if (b[i] == 'A') pma[1][i]++;
			if (b[i] == 'T') pmt[1][i]++;
			if (b[i] == 'C') pmc[1][i]++;
		}
	}
}

int get_distance(int x, int y) {
	int aa, ab, ta, tb, ca, cb, ma, mt, mc, dif;
	aa = pa[0][y] - (x == 0 ? 0 : pa[0][x-1]);
	ab = pa[1][y] - (x == 0 ? 0 : pa[1][x-1]);

	ta = pt[0][y] - (x == 0 ? 0 : pt[0][x-1]);
	tb = pt[1][y] - (x == 0 ? 0 : pt[1][x-1]);

	ca = pc[0][y] - (x == 0 ? 0 : pc[0][x-1]);
	cb = pc[1][y] - (x == 0 ? 0 : pc[1][x-1]);

	ma = pma[0][y] - (x == 0 ? 0 : pma[0][x-1]);
	mt = pmt[0][y] - (x == 0 ? 0 : pmt[0][x-1]);
	mc = pmc[0][y] - (x == 0 ? 0 : pmc[0][x-1]);

	dif = pdif[y] - (x == 0 ? 0 : pdif[x-1]);

	if (aa != ab || ta != tb || ca != cb) return -1;

	if (!(aa && ta && ca)) {
		return dif/2 + dif%2;
	}
	else {
		int mn = min({ma, mt, mc});
		return (dif-mn)/2 + mn;
	}
}
#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...