# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
585325 | cfalas | Mutating DNA (IOI21_dna) | C++17 | 46 ms | 10220 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;
int m[3][3][200000];
int x[256];
int cc[200000];
int Aa[200000];
int Ta[200000];
int Ca[200000];
int Ab[200000];
int Tb[200000];
int Cb[200000];
void init(std::string a, std::string b) {
x['A'] = 0;
x['T'] = 1;
x['C'] = 2;
int n = a.size();
for(int i=0;i<n;i++){
Aa[i+1] = Aa[i] + (a[i]=='A');
Ta[i+1] = Ta[i] + (a[i]=='T');
Ca[i+1] = Ca[i] + (a[i]=='C');
Ab[i+1] = Ab[i] + (b[i]=='A');
Tb[i+1] = Tb[i] + (b[i]=='T');
Cb[i+1] = Cb[i] + (b[i]=='C');
for(int j=0;j<3;j++){
for(int k=0;k<3;k++) m[j][k][i+1] = m[j][k][i];
}
m[x[a[i]]][x[b[i]]][i+1] = m[x[a[i]]][x[b[i]]][i] + 1;
cc[i+1] = cc[i] + (a[i]==b[i]);
//cout<<Aa[i+1]<<" "<<Ta[i+1]<<" "<<Ca[i+1]<<" "<<cc[i+1]<<endl;
}
}
int get_distance(int x, int y) {
x++, y++;
if(Aa[y]-Aa[x-1] != Ab[y]-Ab[x-1]) return -1;
if(Ta[y]-Ta[x-1] != Tb[y]-Tb[x-1]) return -1;
if(Ca[y]-Ca[x-1] != Cb[y]-Cb[x-1]) return -1;
int tot=0;
int tot2=0;
for(int i=0;i<3;i++){
for(int j=i+1;j<3;j++){
tot += abs((m[i][j][y]-m[i][j][x-1]) - (m[j][i][y]-m[j][i][x-1]));
tot2 += min((m[i][j][y]-m[i][j][x-1]), (m[j][i][y]-m[j][i][x-1]));
}
}
//cout<<tot2<<" "<<tot<<endl;
return tot/3 * 2 + tot2;
}
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... |