Submission #1037866

#TimeUsernameProblemLanguageResultExecution timeMemory
1037866vjudge1Mutating DNA (IOI21_dna)C++17
100 / 100
27 ms7760 KiB
#include<bits/stdc++.h>
#include "dna.h"

using namespace std;

const int sz = 1e5 + 5;

map<char, int> en;
int p[sz][3][3];
int n;

string s, t;

void init(string a, string b) {
    n = a.size();
    s = ' ' + a, t = ' ' + b;

    en['A'] = 0, en['T'] = 1, en['C'] = 2;

    for (int i = 1; i <= n; i++) {
        if (s[i] != t[i]) {
            int a = en[s[i]];
            int b = en[t[i]];
            p[i][a][b] ++;
        }

        for (int j = 0; j < 3; j ++) {
            for (int k = 0; k < 3; k ++) {
                p[i][j][k] += p[i - 1][j][k];
            }
        }
    }
}

int get_distance(int x, int y) {
    x ++, y ++;
    bool v[3][3] {};
    int cn[3] {};
    int d = 0;
    for (int i = 0; i < 3; i ++) {
        for (int j = 0; j < 3; j ++) {
            int cnj = p[y][i][j] - p[x - 1][i][j];
            int cni = p[y][j][i] - p[x - 1][j][i];
            if (cni >= cnj && !v[j][i]) {
                cn[i] += cni - cnj;
                d += cnj;
                v[i][j] = true;
            }
        }
    }
    if (cn[0] == cn[1] && cn[1] == cn[2]) {
        d += cn[0] * 2;
    } else {
        return -1;
    }
    return d;
}
#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...