Submission #542261

# Submission time Handle Problem Language Result Execution time Memory
542261 2022-03-26T03:07:39 Z apocryphal44 Mutating DNA (IOI21_dna) C++17
0 / 100
34 ms 2380 KB
#include<string>
//#include<iostream>
using namespace std;
string s_a, s_b;

class DNA{
	public:
		string str_{};
		int A_count{0}, T_count{0}, C_count{0};

		DNA (string a) : str_(a) {
	for (auto i: str_){
		switch((int)i){
			case 65:
				this->A_count++;
				break;
			case 67:
				this->C_count++;
				break;
			case 84:
				this->T_count++;
				break;
			default:
				break;
		}}}

};

void init(string a, string b){
	s_a=a;
	s_b=b;

}

int get_distance(int x, int y){

	// Feasible Check
	const int len{(y-x)+1};
	DNA a_sub{s_a.substr((long long unsigned int)x, (long long unsigned int)len)};
	DNA b_sub{s_b.substr((long long unsigned int)x, (long long unsigned int)len)};

	if ((a_sub.A_count != b_sub.A_count) or (a_sub.C_count != b_sub.C_count) or (a_sub.T_count != b_sub.T_count)) return -1;

	// Greedy Algorithm
	int r{0}, i{0};
	for( auto j : a_sub.str_){

		char b_i = b_sub.str_.at((long long unsigned int)i);
		if (b_i != j)
		{
			for (int k{i+1}; k<len; k++){
				if (b_sub.str_.at((long long unsigned int)k) == j)
				{
					b_sub.str_[(long long unsigned int)i] = j;
					b_sub.str_[(long long unsigned int)k] = b_i;
					r++;
					break;
				}
			}
		}
		i++;
	}
	return r;
	
}

/*
int main(){
	string str1, str2;
	int a,b;
	cin >> str1 >> str2;
	init(str1, str2);
	cin >> a >> b;
	cout << get_distance(a,b);
	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 2380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 980 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 980 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 980 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 2380 KB Output isn't correct
2 Halted 0 ms 0 KB -