제출 #1142029

#제출 시각아이디문제언어결과실행 시간메모리
1142029programming23DNA 돌연변이 (IOI21_dna)C++20
0 / 100
1612 ms1769640 KiB
#include "bits/stdc++.h"
using namespace std;

string stringA="";
string stringB="";
map<string, int> answers;

void init(string a, string b) {
	stringA = a;
	stringB = b;
}

int get_distance(int x, int y) {
	string sA = stringA;
	string sB = stringB;
	map<char, int> countsB;
	map<char, int> countsA;
	int count = 0;
	for(int i=x; i <= y; i++){
		if(countsA.find(sA[i]) == countsA.end()){
			countsA[sA[i]] = 1;
		}else{
			countsA[sA[i]] +=1;
		}
		if(countsB.find(sB[i]) == countsB.end()){
			countsB[sB[i]] = 1;
		}else{
			countsB[sB[i]] +=1;
		}
	}
    int lnA = countsA.size();
    int lnB = countsB.size();
	if(lnA != lnB){
		return -1;
	}for(auto c: countsA){
		if(countsA[c.first] != countsB[c.first]){
			return -1;
		}
	}
    int i=x;
    while (i <= y && sA != sB){
        char c = sA[i];
        string t = sA.substr(i, y) + ":"+sB.substr(i, y) ;
        if(answers.find(t) != answers.end()){
            count += answers[t];
            break;
        }
        if(c == sB[i]){
            i++;
            continue;
        }
        for(int z=i+1; z <= y; z++){
            if(sA[z] != sB[i] || sA[z] == sB[z]){
                continue;
            }
            sA[i] = sA[z];
            sA[z] = c;
            if(lnA == 2 && lnB == 2){
                i = z+1;
            }
            else{
                i++;
            }
            count++;
        }
    }
    answers[sA.substr(x, y) + ":" + sB.substr(x, y)] = count;
	return count;
}
#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...