제출 #713855

#제출 시각아이디문제언어결과실행 시간메모리
713855thinknoexitDNA 돌연변이 (IOI21_dna)C++17
100 / 100
57 ms9712 KiB
#include "dna.h" int dp1[3][100100], dp2[3][100100]; int dp[3][3][100100]; char h[26]; void init(std::string a, std::string b) { h[0] = 0; h['T' - 'A'] = 1; h['C' - 'A'] = 2; for (int i = 1;i <= (int)a.size();i++) { char c = a[i - 1]; dp1[0][i] = dp1[0][i - 1] + (c == 'A'); dp1[1][i] = dp1[1][i - 1] + (c == 'T'); dp1[2][i] = dp1[2][i - 1] + (c == 'C'); } for (int i = 1;i <= (int)b.size();i++) { char c = b[i - 1]; dp2[0][i] = dp2[0][i - 1] + (c == 'A'); dp2[1][i] = dp2[1][i - 1] + (c == 'T'); dp2[2][i] = dp2[2][i - 1] + (c == 'C'); } for (int i = 1;i <= (int)a.size();i++) { for (int j = 0;j < 3;j++) { for (int k = 0;k < 3;k++) { dp[j][k][i] = dp[j][k][i - 1] + (h[a[i - 1] - 'A'] == j && h[b[i - 1] - 'A'] == k); } } } } int get_distance(int x, int y) { int l = x, r = y; r++, l++; bool ch = 1; for (int k = 0;k < 3;k++) { ch &= (dp1[k][r] - dp1[k][l - 1] == dp2[k][r] - dp2[k][l - 1]); } if (!ch) { return -1; } int now[3][3] = {}; for (int i = 0;i < 3;i++) { for (int j = 0;j < 3;j++) { now[i][j] = dp[i][j][r] - dp[i][j][l - 1]; } } int cnt = 0; for (int i = 0;i < 3;i++) { for (int j = i + 1;j < 3;j++) { int mn; if (now[i][j] > now[j][i]) mn = now[j][i]; else mn = now[i][j]; cnt += mn; now[i][j] -= mn; now[j][i] -= mn; } } int cnt2 = 0; for (int i = 0;i < 3;i++) { for (int j = 0;j < 3;j++) { if (i == j) continue; cnt2 += now[i][j]; } } return cnt + cnt2 * 2 / 3; }
#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...