Submission #1330049

#TimeUsernameProblemLanguageResultExecution timeMemory
1330049nicolo_010DNA 돌연변이 (IOI21_dna)C++20
35 / 100
31 ms14128 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string a, b;
vector<vector<int>> ama, amb;
vector<int> pref;

void init(std::string A, std::string B) {
	a = A, b = B;
	int n = a.size();
	pref.assign(n, 0);
	ama.assign(n, vector<int>(3, 0));
	amb = ama;
	map<char, int> mp;
	mp['A'] = 0;
	mp['C'] = 1;
	mp['T'] = 2;
	for (int i=0; i<n; i++) {
		int at = (i==0 ? 0 : pref[i-1]);
		pref[i] = at + (a[i]!=b[i]);

		for (int j=0; j<3; j++) {
			int at = (i==0 ? 0 : ama[i-1][j]);
			ama[i][j] = at;
			at = (i==0 ? 0 : amb[i-1][j]);
			amb[i][j] = at;
		}
		ama[i][mp[a[i]]]++;
		amb[i][mp[b[i]]]++;
	}
}

int get_distance(int x, int y) {
	int det = (x==0 ? 0 : pref[x-1]);
	int cnt = pref[y]-det;

	//calcular apariciones de A
	det = (x==0 ? 0 : ama[x-1][0]);
	int A = ama[y][0] - det;
	det = (x==0 ? 0 : amb[x-1][0]);
	int B = amb[y][0] - det;
	if (A!=B) return -1;

	//calcular apariciones de T
	det = (x==0 ? 0 : ama[x-1][2]);
	A = ama[y][2] - det;
	det = (x==0 ? 0 : amb[x-1][2]);
	B = amb[y][2] - det;
	if (A!=B) return -1;
	return cnt/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...