제출 #783715

#제출 시각아이디문제언어결과실행 시간메모리
783715mousebeaverDNA 돌연변이 (IOI21_dna)C++17
100 / 100
34 ms8952 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; const int N = 100000; int diff[N]; int Aa[N]; int Ca[N]; int Ab[N]; int Cb[N]; int ind(char c) { if(c == 'A') { return 0; } else if(c == 'C') { return 1; } return 2; } int adjlist[N][3][3]; //Letter string a, letter string b void init(std::string a, std::string b) { Aa[0] = (a[0] == 'A'); Ca[0] = (a[0] == 'C'); Ab[0] = (b[0] == 'A'); Cb[0] = (b[0] == 'C'); for(int c = 0; c < 3; c++) { for(int d = 0; d < 3; d++) { adjlist[0][c][d] = 0; } } adjlist[0][ind(a[0])][ind(b[0])] = 1; int n = a.length(); for(int i = 1; i < n; i++) { Aa[i] = Aa[i-1]+(a[i] == 'A'); Ca[i] = Ca[i-1]+(a[i] == 'C'); Ab[i] = Ab[i-1]+(b[i] == 'A'); Cb[i] = Cb[i-1]+(b[i] == 'C'); for(int c = 0; c < 3; c++) { for(int d = 0; d < 3; d++) { adjlist[i][c][d] = adjlist[i-1][c][d]; } } adjlist[i][ind(a[i])][ind(b[i])]++; } } int get_distance(int x, int y) { if(Aa[y] - (x == 0 ? 0 : Aa[x-1]) != Ab[y] - (x== 0 ? 0 : Ab[x-1]) || Ca[y] - (x == 0 ? 0 : Ca[x-1]) != Cb[y] - (x== 0 ? 0 : Cb[x-1])) { return -1; } int counter[3][3]; for(int c = 0; c < 3; c++) { for(int d = 0; d < 3; d++) { counter[c][d] = adjlist[y][c][d] - (x == 0 ? 0 : adjlist[x-1][c][d]); } } int output = 0; for(int i = 0; i < 3; i++) { counter[i][i] = 0; for(int j = 0; j < 3; j++) { if(i == j) continue; int m = min(counter[i][j], counter[j][i]); counter[i][j] -= m; counter[j][i] -= m; output += m; } } output += max(counter[0][1], counter[0][2])*2; return output; }
#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...