제출 #639765

#제출 시각아이디문제언어결과실행 시간메모리
639765studyMutating DNA (IOI21_dna)C++17
100 / 100
44 ms6112 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+1;

int psum[3][3][N];

char c(char a){
	if (a == 'A') return 0;
	if (a == 'C') return 1;
	return 2;
}

void init(string a, string b){
	for (int i=0; i<a.size(); ++i){
		int idx = i+1;
		for (int A=0; A<3; ++A){
			for (int B=0; B<3; ++B){
				psum[A][B][idx] += psum[A][B][idx-1];
			}
		}
		psum[c(a[i])][c(b[i])][idx]++;
	}
}

int get_distance(int x, int y){
	x++; y++;
	vector<int> check(3);
	int ans = 0, crt = 0;
	for (int A=0; A<3; ++A){
		for (int B=A+1; B<3; ++B){
			int val1 = psum[A][B][y]-psum[A][B][x-1], val2 = psum[B][A][y]-psum[B][A][x-1];
			check[A] += val1;
			check[B] -= val1;
			check[B] += val2;
			check[A] -= val2;
			ans += min(val1,val2);
			crt += abs(val1-val2);
		}
	}
	if (check[0] or check[1] or check[2]) return -1;
	return ans+2*crt/3;
}

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

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:15:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  for (int i=0; i<a.size(); ++i){
      |                ~^~~~~~~~~
dna.cpp:22:9: warning: array subscript has type 'char' [-Wchar-subscripts]
   22 |   psum[c(a[i])][c(b[i])][idx]++;
      |        ~^~~~~~
dna.cpp:22:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   22 |   psum[c(a[i])][c(b[i])][idx]++;
      |                 ~^~~~~~
#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...