제출 #982486

#제출 시각아이디문제언어결과실행 시간메모리
982486faqinyeagerDNA 돌연변이 (IOI21_dna)C++17
100 / 100
38 ms9680 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; int n; int asum[100050][3], bsum[100050][3]; int cnt[100050][3][3]; void init(std::string a, std::string b){ n = (int)a.size(); for(int i = 0; i < n; i ++){ if(a[i] == 'A') asum[i + 1][0] ++; else if(a[i] == 'C') asum[i + 1][1] ++; else asum[i + 1][2] ++; if(b[i] == 'A') bsum[i + 1][0] ++; else if(b[i] == 'C') bsum[i + 1][1] ++; else bsum[i + 1][2] ++; int ai = 2, bi = 2; if(a[i] == 'A') ai = 0; else if(a[i] == 'C') ai = 1; if(b[i] == 'A') bi = 0; else if(b[i] == 'C') bi = 1; cnt[i + 1][ai][bi] = 1; } for(int i = 2; i <= n; i ++){ for(int j = 0; j < 3; j ++){ asum[i][j] += asum[i - 1][j]; bsum[i][j] += bsum[i - 1][j]; } for(int j = 0; j < 3; j ++){ for(int jj = 0; jj < 3; jj ++){ cnt[i][j][jj] += cnt[i - 1][j][jj]; } } } } int get_distance(int x, int y){ x++, y++; for(int j = 0; j < 3; j ++){ if(asum[y][j] - asum[x - 1][j] != bsum[y][j] - bsum[x - 1][j]){ return -1; } } int c[3][3] = {{0}}; for(int j = 0; j < 3; j ++){ for(int jj = 0; jj < 3; jj ++){ c[j][jj] = cnt[y][j][jj] - cnt[x - 1][j][jj]; } } int tmp = min(c[0][1], c[1][0]), ans = 0; c[0][1] -= tmp, c[1][0] -= tmp, ans += tmp; tmp = min(c[0][2], c[2][0]); c[0][2] -= tmp, c[2][0] -= tmp, ans += tmp; tmp = min(c[1][2], c[2][1]); c[1][2] -= tmp, c[2][1] -= tmp, ans += tmp; ans += 2 * (c[0][1] + c[1][0]); return ans; } // aaaacccctt // ccccaattaa
#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...