제출 #540288

#제출 시각아이디문제언어결과실행 시간메모리
540288colossal_pepeDNA 돌연변이 (IOI21_dna)C++17
100 / 100
38 ms7648 KiB
#include <iostream>
#include <cstring>
using namespace std;

int n;
string s1, s2;
int cnt[100005][3][3];

int id(char c) {
    if (c == 'A') return 0;
    else if (c == 'T') return 1;
    else return 2;
}

void beautifyData() {
    for (int i = 0; i < n; i++) {
        cnt[i][id(s1[i])][id(s2[i])] = 1;
        if (i > 0) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    cnt[i][j][k] += cnt[i - 1][j][k];
                }
            }
        }
    }
}

void init(string a, string b) {
    s1 = a, s2 = b;
    n = a.size();
    beautifyData();
}

int get_distance(int x, int y) {
    int mat[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            mat[i][j] = cnt[y][i][j] - (x > 0 ? cnt[x - 1][i][j] : 0);
        }
    }
    for (int i = 0; i < 3; i++) {
        if (mat[i][0] + mat[i][1] + mat[i][2] != mat[0][i] + mat[1][i] + mat[2][i]) return -1;
    }
    int ans = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = i + 1; j < 3; j++) {
            int moves = min(mat[i][j], mat[j][i]);
            ans += moves;
            mat[i][j] -= moves;
            mat[j][i] -= moves;
            mat[i][i] += moves;
            mat[j][j] += moves;
        }
    }
    ans += mat[0][1];
    mat[2][1] += mat[0][1];
    mat[0][1] = 0;
    ans += mat[0][2];
    mat[1][2] += mat[0][2];
    mat[0][2] -= 0;
    ans += mat[2][1];
    mat[2][1] = mat[1][2] = 0;
    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...