Submission #1009620

#TimeUsernameProblemLanguageResultExecution timeMemory
1009620oyberMutating DNA (IOI21_dna)C++17
71 / 100
1520 ms4568 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> a;
vector<int> b;
int n;

int char_to_num(char c) {
	if (c == 'A') {
		return 0;
	}
	if (c == 'C') {
		return 1;
	}
	return 2;
}

void init(string A, string B) {
	n = A.size();

	for (int i = 0; i < n; i++) {
		a.push_back(char_to_num(A[i]));
		b.push_back(char_to_num(B[i]));
	}
}

int get_distance(int x, int y) {
	vector<int> num(9);
	for (int i = x; i <= y; i++) {
		//printf("%d %d\n", a[i], b[i]);
		num[a[i]*3+b[i]]++;
	}

	if (!(num[0]+num[3]+num[6] == num[0]+num[1]+num[2] && num[1]+num[4]+num[7] == num[3]+num[4]+num[5])) {
		return -1;
	}

	int swaps = 0;

	int ac = min(num[1], num[3]);
	swaps += ac;
	num[1] -= ac;
	num[3] -= ac;

	int at = min(num[2], num[6]);
	swaps += at;
	num[2] -= at;
	num[6] -= at;

	int ct = min(num[5], num[7]);
	swaps += ct;
	num[5] -= ct;
	num[7] -= ct;

	int s = num[1]+num[3]+num[2]+num[6]+num[5]+num[7];
	swaps += (s/3)*2;

	return swaps;
}
#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...