제출 #437167

#제출 시각아이디문제언어결과실행 시간메모리
437167CaDeDNA 돌연변이 (IOI21_dna)C++17
100 / 100
56 ms6020 KiB
#include "dna.h"
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <map>
using namespace std;
const int maxN = 100005;
int pre[maxN][3][3];
map<int, int> mappea;
void init(std::string a, std::string b) {
	
	mappea.insert(make_pair('C', 0));
	mappea.insert(make_pair('A', 1));
	mappea.insert(make_pair('T', 2));
	
	
	for(int i = 0; i <3;++i)
	for(int j = 0; j <3; ++j)
		pre[0][i][j] = 0;
	pre[0][mappea[a[0]]][mappea[b[0]]]++;

	for(int k = 1; k < a.size(); ++k){
		for(int i = 0; i <3;++i)
		for(int j = 0; j <3; ++j)
			pre[k][i][j] = pre[k-1][i][j];
		pre[k][mappea[a[k]]][mappea[b[k]]]++;
	}
}

int get_distance(int x, int y) {
	
	int mat[3][3];
	for(int i = 0; i <3;++i)
	for(int j = 0; j <3; ++j){
		mat[i][j] = pre[y][i][j];
		if(x > 0) mat[i][j] -= pre[x-1][i][j];
	}

	for(int i = 0; i <3; ++i){
		int num = 0, num2 = 0;
		for(int j = 0; j < 3; ++j){
			num += mat[i][j];
			num2 += mat[j][i];
		}
		if(num != num2) return -1;
	}
	int resp = 0;
	for(int i = 0; i < 3; ++i){
		for(int j = i+1; j < 3; ++j){
			int cicloDos = min(mat[i][j], mat[j][i]);
			mat[i][j] -= cicloDos;
			mat[j][i] -= cicloDos;
			resp += cicloDos;
		}
	}
	int ciclotres =0;
	for(int i = 0; i <3;++i)
		for(int j = 0; j <3; ++j)
			if(i != j)
				ciclotres += mat[i][j];
	resp += 2*ciclotres/3;
	return resp;
}

컴파일 시 표준 에러 (stderr) 메시지

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int k = 1; k < a.size(); ++k){
      |                 ~~^~~~~~~~~~
#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...