Submission #600366

#TimeUsernameProblemLanguageResultExecution timeMemory
600366OrazBDNA 돌연변이 (IOI21_dna)C++17
22 / 100
1590 ms58536 KiB
#include <bits/stdc++.h>
#include "dna.h"
#define N 100005
#define wr cout << "Continue debugging\n";
#define ll long long int
#define pii pair <string, int>
#define pb push_back
#define ff first
#define ss second
using namespace std;

map <pii, int> pr;
map <string, int> m;
vector <string> v = {"AT", "TA", "AC", "CA", "CT", "TC"};

void init(string a, string b){
	int n = a.size();
	a = ' ' + a;
	b = ' ' + b;
	for (int i = 1; i <= n; i++){
		if (a[i] != b[i]){
			string s = "";
			s += a[i]; 
			s += b[i];	
			pr[{s, i}] = 1;
		} 
	}
	for (int i = 2; i <= n; i++){
		for (auto s : v) pr[{s, i}] += pr[{s, i - 1}];
	}
}
int get_distance(int l, int r){
	for (auto s : v) m[s] = 0;
	l++; r++;
	int ans = 0;
	for (auto s : v) m[s] = pr[{s, r}] - pr[{s, l - 1}]; 
	int mn = min(m[v[0]], m[v[1]]);
	ans += mn;
	m[v[0]] -= mn;
	m[v[1]] -= mn;
	mn = min(m[v[2]], m[v[3]]);
	ans += mn;
	m[v[2]] -= mn;
	m[v[3]] -= mn;
	mn = min(m[v[4]], m[v[5]]);
	ans += mn;
	m[v[4]] -= mn;
	m[v[5]] -= mn;
	for (auto s : v){
		string c = "", t1 = "";
		c += s[1];
		if ('A' != s[0] and 'A' != s[1]) c += 'A';
		else if ('T' != s[0] and 'T' != s[1]) c += 'T';
		else c += 'C';
		t1 += s[0];
		t1 += c[1];
		int mn = min(m[s], m[c]);
		ans += mn;
		m[s] -= mn;
		m[c] -= mn;
		m[t1] += mn;
	}
	// mn = min(m[v[0]], m[v[1]]);
	// ans += mn;
	// m[v[0]] -= mn;
	// m[v[1]] -= mn;
	// mn = min(m[v[2]], m[v[3]]);
	// ans += mn;
	// m[v[2]] -= mn;
	// m[v[3]] -= mn;
	// mn = min(m[v[4]], m[v[5]]);
	// ans += mn;
	// m[v[4]] -= mn;
	// m[v[5]] -= mn;
	for (auto i : v) if (m[i]) return -1;
	return ans;
}
// int main ()
// {
// 	ios::sync_with_stdio(false);
// 	cin.tie(0);
// 	int n1, q1;
// 	string a, b;
// 	cin >> n1 >> q1 >> a >> b;
// 	init(a, b);
// 	while(q1--){
// 		int x, y;
// 		cin >> x >> y;	
// 		cout << get_distance(x, y);
// 	}
// }	
#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...