제출 #657896

#제출 시각아이디문제언어결과실행 시간메모리
657896benjaminkleynDNA 돌연변이 (IOI21_dna)C++17
100 / 100
37 ms7432 KiB
#include <bits/stdc++.h>
#include "dna.h"
using namespace std;
typedef long long ll;

int n;
int pref[3][3][100001];
void init(string A, string B)
{
    n = A.size();
    for (int i = 0; i < n; i++)
    {
        for (int a = 0; a < 3; a++)
            for (int b = 0; b < 3; b++)
                pref[a][b][i + 1] = pref[a][b][i];

        int a = (A[i] == 'C') + 2 * (A[i] == 'T');
        int b = (B[i] == 'C') + 2 * (B[i] == 'T');
        pref[a][b][i + 1]++;
    }
}

int cnt[3][3];
int get_distance(int x, int y)
{
    for (int a = 0; a < 3; a++)
        for (int b = 0; b < 3; b++)
            cnt[a][b] = pref[a][b][y + 1] - pref[a][b][x];

    for (int i = 0; i < 3; i++)
        if (cnt[i][0] + cnt[i][1] + cnt[i][2] != cnt[0][i] + cnt[1][i] + cnt[2][i])
            return -1;

    int res = min(cnt[0][1], cnt[1][0]) + min(cnt[1][2], cnt[2][1]) + min(cnt[2][0], cnt[0][2]);
    return res + (max(cnt[0][1], cnt[1][0]) - min(cnt[0][1], cnt[1][0])) * 2;
}
#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...