제출 #1214284

#제출 시각아이디문제언어결과실행 시간메모리
1214284trimkusMutating DNA (IOI21_dna)C++20
0 / 100
34 ms7488 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;


map<char, int> mp;
string a, b;
const int MAXN = 1e5;
int tot[MAXN][3][3], tbal[MAXN][3], same[MAXN];

void init(std::string _a, std::string _b) {
	a = _a;
	b = _b;
	mp['A'] = 0;
	mp['T'] = 1;
	mp['C'] = 2;
	int n = a.size();
	for (int i = 0; i < n; ++i) {
		int ai = mp[a[i]];
		int bi = mp[b[i]];
		tbal[i][ai] += 1;
		tbal[i][bi] -= 1;
		tot[i][ai][bi] += 1;
		same[i] = (ai == bi);
		if (i) {
			for (int j = 0; j < 3; ++j) {
				tbal[i][j] += tbal[i - 1][j];
			}
			for (int j = 0; j < 3; ++j) {
				for (int k = 0; k < 3; ++k) {
					tot[i][j][k] += tot[i - 1][j][k];
				}
			}
			same[i] += same[i - 1];
		}
	}
}
// 1, 2, 4
// 8, 16, 32
int get_distance(int x, int y) {
	vector<vector<int>> cnt(3, vector<int>(3));
	vector<int> bal(3);
	int res = 0;
	for (int i = 0; i < 3; ++i) {
		bal[i] = tbal[y][i] - (x - 1 >= 0 ? tbal[x - 1][i] : 0);
	}
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cnt[i][j] = tot[y][i][j] - (x - 1 >= 0 ? tot[x - 1][i][j] : 0);  
		} 
	}
	int left = y - x + 1 - (same[y] - (x - 1 >= 0 ? same[x - 1] : 0));
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			int take = min(cnt[i][j], cnt[j][i]);
			cnt[i][j] -= take;
			cnt[j][i] -= take;
			left -= 2 * take;
			res += take;
		}
	}
	for (auto& i : bal) {
		if (i != 0) return -1;
	}
	// cerr << "[" << a.substr(x, y - x + 1) << " , " << b.substr(x, y - x + 1) << "] = " << res << "\n";
	// assert(res % 2 == 0);
	// cerr << left << "\n";
	// assert(left % 3 == 0);
	return res + (left / 3) * 2;
}
#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...