제출 #442803

#제출 시각아이디문제언어결과실행 시간메모리
442803alan8585DNA 돌연변이 (IOI21_dna)C++17
100 / 100
87 ms6016 KiB
#include "dna.h" #include <vector> using namespace std; int n, pre[100100][3][3]; int tran(char c) { if(c == 'A') return 0; if(c == 'T') return 1; return 2; } void init(std::string a, std::string b) { n = a.size(); for(int i = 0; i < n; i++) { int x = tran(a[i]), y = tran(b[i]); for(int j = 0; j < 3; j++) { for(int k = 0; k < 3; k++) { pre[i + 1][j][k] = pre[i][j][k] + (j == x && k == y); } } } } int get_distance(int x, int y) { x++, y++; vector<int> acnt(3), bcnt(3); vector<vector<int>> m(3, vector<int>(3)); for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { acnt[i] += pre[y][i][j] - pre[x - 1][i][j]; bcnt[j] += pre[y][i][j] - pre[x - 1][i][j]; m[i][j] = pre[y][i][j] - pre[x - 1][i][j]; } } for(int i = 0; i < 3; i++) if(acnt[i] != bcnt[i]) return -1; int ans = 0; for(int i = 0; i < 3; i++) { for(int j = i + 1; j < 3; j++) { int now = min(m[i][j], m[j][i]); m[i][j] -= now; m[j][i] -= now; ans += now; } } if(m[0][1]) { if(m[0][1] != m[1][2] || m[0][1] != m[2][0]) while(1); if(m[0][2] || m[1][0] || m[2][1]) while(1); ans += m[0][1] * 2; } else if(m[0][2]) { if(m[0][2] != m[1][0] || m[0][2] != m[2][1]) while(1); if(m[0][1] || m[1][2] || m[2][0]) while(1); ans += m[0][2] * 2; } return ans; }
#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...