제출 #996893

#제출 시각아이디문제언어결과실행 시간메모리
996893toast12DNA 돌연변이 (IOI21_dna)C++17
0 / 100
14 ms4180 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;

map<string, vector<int>> ps;
int n;

void init(string a, string b) {
	n = a.size();
	map<string, int> prev;
	for (int i = 0; i < n; i++) {
		string s = to_string(a[i])+to_string(b[i]);
		ps["AT"].push_back(prev["AT"]);
		ps["AC"].push_back(prev["AC"]);
		ps["CA"].push_back(prev["CA"]);
		ps["CT"].push_back(prev["CT"]);
		ps["TA"].push_back(prev["TA"]);
		ps["TC"].push_back(prev["TC"]);
		ps[s][ps[s].size()-1]++;
		prev["AT"] = ps["AT"].back();
		prev["AC"] = ps["AC"].back();
		prev["CA"] = ps["CA"].back();
		prev["CT"] = ps["CT"].back();
		prev["TA"] = ps["TA"].back();
		prev["TC"] = ps["TC"].back();
	}
}

int get_distance(int x, int y) {
	map<string, int> cnt;
	if (x > 0) {
		cnt["AT"] = ps["AT"][y]-ps["AT"][x-1];
		cnt["AC"] = ps["AC"][y]-ps["AC"][x-1];
		cnt["CA"] = ps["CA"][y]-ps["CA"][x-1];
		cnt["CT"] = ps["CT"][y]-ps["CT"][x-1];
		cnt["TA"] = ps["TA"][y]-ps["TA"][x-1];
		cnt["TC"] = ps["TC"][y]-ps["TC"][x-1];
	}
	else {
		cnt["AT"] = ps["AT"][y];
		cnt["AC"] = ps["AC"][y];
		cnt["CA"] = ps["CA"][y];
		cnt["CT"] = ps["CT"][y];
		cnt["TA"] = ps["TA"][y];
		cnt["TC"] = ps["TC"][y];
	}
	int ans = 0;
	int t = min(cnt["TA"], cnt["AT"]);
	ans += t;
	cnt["TA"] -= t, cnt["AT"] -= t;
	t = min(cnt["AC"], cnt["CA"]);
	ans += t;
	cnt["AC"] -= t, cnt["CA"] -= t;
	t = min(cnt["CT"], cnt["TC"]);
	ans += t;
	cnt["CT"] -= t, cnt["TC"] -= t;
	t = min({cnt["AT"], cnt["TC"], cnt["CA"]});
	ans += 2*t;
	cnt["AT"] -= t, cnt["TC"] -= t, cnt["CA"] -= t;
	t = min({cnt["TA"], cnt["AC"], cnt["CT"]});
	ans += 2*t;
	cnt["TA"] -= t, cnt["AC"] -= t, cnt["CT"] -= t;
	if (cnt["AT"] || cnt["TA"] || cnt["AC"] || cnt["CA"] || cnt["TC"] || cnt["CT"])
		ans = -1;
	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...