# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
477678 | TairitsuOwO | Mutating DNA (IOI21_dna) | C++17 | 43 ms | 8012 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
const int mxn=1e5+9;
int counta[mxn][3], countb[mxn][3], arr[mxn][3][3];
void init(string a, string b) {
auto f=[](char c)->int{
return c=='A'? 0: c=='T'? 1: 2;
};
a=" "+a, b=" "+b;
for (int i=1; i<a.length(); i++){
for (int j=0; j<3; j++) for (int k=0; k<3; k++){
arr[i][j][k]=arr[i-1][j][k];
counta[i][j]=counta[i-1][j];
countb[i][j]=countb[i-1][j];
}
counta[i][f(a[i])]++;
countb[i][f(b[i])]++;
arr[i][f(a[i])][f(b[i])]++;
}
}
int get_distance(int x, int y) {
x++, y++;
for (int i=0; i<3; i++) if (counta[y][i]-counta[x-1][i]!=countb[y][i]-countb[x-1][i]) return -1;
int tmp[3][3], res=0;
for (int i=0; i<3; i++) for (int j=0; j<3; j++) tmp[i][j]=arr[y][i][j]-arr[x-1][i][j];
for (int i=0; i<3; i++) for (int j=i+1; j<3; j++){
int swaps=min(tmp[i][j], tmp[j][i]);
tmp[i][j]-=swaps, tmp[j][i]-=swaps, res+=swaps;
}
int res2=0;
for (int i=0; i<3; i++) for (int j=0; j<3; j++) res2+=tmp[i][j];
return res+res2*2/3;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |