# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
639765 | study | Mutating DNA (IOI21_dna) | C++17 | 44 ms | 6112 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 <bits/stdc++.h>
using namespace std;
const int N = 1e5+1;
int psum[3][3][N];
char c(char a){
if (a == 'A') return 0;
if (a == 'C') return 1;
return 2;
}
void init(string a, string b){
for (int i=0; i<a.size(); ++i){
int idx = i+1;
for (int A=0; A<3; ++A){
for (int B=0; B<3; ++B){
psum[A][B][idx] += psum[A][B][idx-1];
}
}
psum[c(a[i])][c(b[i])][idx]++;
}
}
int get_distance(int x, int y){
x++; y++;
vector<int> check(3);
int ans = 0, crt = 0;
for (int A=0; A<3; ++A){
for (int B=A+1; B<3; ++B){
int val1 = psum[A][B][y]-psum[A][B][x-1], val2 = psum[B][A][y]-psum[B][A][x-1];
check[A] += val1;
check[B] -= val1;
check[B] += val2;
check[A] -= val2;
ans += min(val1,val2);
crt += abs(val1-val2);
}
}
if (check[0] or check[1] or check[2]) return -1;
return ans+2*crt/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... |