Submission #1179605

#TimeUsernameProblemLanguageResultExecution timeMemory
1179605madamadam3DNA 돌연변이 (IOI21_dna)C++20
21 / 100
28 ms2376 KiB
#include "dna.h"
#include <bits/stdc++.h>

using namespace std;

string A, B;

string subs(string &inp, int x, int y) {
	string out = "";
	for (int i = x; i <= y; i++) out = out + inp[i];
	return out;
}

string stridx(string &inp, int i) {
	string out = "" + inp[i];
	return out;
}

template<typename Tuple>
string assemble(string &inp, const Tuple &indices) {
    string out = "";
    std::apply([&](auto... args) {
        ((out += inp[args]), ...);
    }, indices);
    return out;
}

void init(string a, string b) {
	A = a;
	B = b;
}

int get_distance(int x, int y) {
	string sa = subs(A, x, y), sb = subs(B, x, y);
	if (y - x == 0) {
		return sa == sb ? 0 : -1;
	}
	if (y - x == 1) {
		string rb = sb; reverse(rb.begin(), rb.end());
		if (sa == sb) return 0;
		if (sa == rb) return 1;
		else return -1;
	}
	if (y - x == 2) {
		set<string> zero = {sa};
		set<string> one = {assemble(sa, make_tuple(0, 2, 1)), assemble(sa, make_tuple(1, 0, 2)), assemble(sa, make_tuple(2, 1, 0))};
		set<string> two = {assemble(sa, make_tuple(2, 0, 1)), assemble(sa, make_tuple(1, 2, 0))};

		if (zero.count(sb)) return 0;
		else if (one.count(sb)) return 1;
		else if (two.count(sb)) return 2;
		else return -1;
	}
	return -1;
}
#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...