Submission #996778

#TimeUsernameProblemLanguageResultExecution timeMemory
996778overwatch9Mutating DNA (IOI21_dna)C++17
0 / 100
22 ms2392 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string A, B;
void init(std::string a, std::string b) {
	A = a;
	B = b;
}

int get_distance(int x, int y) {
	string a = A.substr(x, y - x + 1);
	string b = B.substr(x, y - x + 1);
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	if (a != b)
		return -1;
	if (y - x + 1 == 1)
		return 0;
	a = A.substr(x, y - x + 1);
	b = B.substr(x, y - x + 1);
	if (a == b)
		return 0;
	if (y - x + 1 == 2)
		return 1;
	ll ans = 0;
	while (a != b) {
		for (int i = 0; i < 3; i++) {
			if (a[i] == b[i])
				continue;
			for (int j = 0; j < 3; j++) {
				if (i == j)
					continue;
				if (b[j] == a[i]) {
					ans += abs(i - j);
					swap(b[i], b[j]);
				}
			}
		}
	}
	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...