제출 #930438

#제출 시각아이디문제언어결과실행 시간메모리
930438SmuggingSpunDNA 돌연변이 (IOI21_dna)C++17
100 / 100
34 ms7192 KiB
#include "dna.h"
#include<bits/stdc++.h>
using namespace std;
const int lim = 1e5 + 5;
int get_id(char c){
	return (c == 'A' ? 0 : 1 + int(c == 'T'));
}
int cnt[lim][3][3];
void init(string a, string b){
	int n = a.size();
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cnt[0][i][j] = 0;
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 3; j++){
			for(int k = 0; k < 3; k++){
				cnt[i][j][k] = cnt[i - 1][j][k] + int(get_id(a[i - 1]) == j && get_id(b[i - 1]) == k);
			}
		}
	}
}
int get_distance(int x, int y) {
	x++;
	y++;
	int cycle, ans = 0;
	for(int i = 0; i < 3; i++){
		int j = (i == 2 ? 0 : i + 1), a = cnt[y][i][j] - cnt[x - 1][i][j], b = cnt[y][j][i] - cnt[x - 1][j][i];
		if(i == 0){
			cycle = a - b;
		}
		else if(cycle != a -b){
			return -1;
		}
		ans += min(a, b);
	}
	return ans + (abs(cycle) << 1);
}

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

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:33:8: warning: 'cycle' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |   else if(cycle != a -b){
      |        ^~
#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...