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"
#ifndef EVAL
#include "grader.cpp"
#endif
#include "bits/stdc++.h"
using namespace std;
#define ar array
const int N = 1e5 + 5;
ar<int, 4> pref[N];
void init(string a, string b) {
int n = a.size();
for(int i=0;i<n;i++){
if(i) pref[i] = pref[i-1];
if(a[i] == b[i]) pref[i][3]++;
else {
if(a[i] == 'A' && b[i] == 'T') pref[i][0]++;
if(a[i] == 'T' && b[i] == 'C') pref[i][1]++;
if(a[i] == 'C' && b[i] == 'A') pref[i][2]++;
swap(a[i], b[i]);
if(a[i] == 'A' && b[i] == 'T') pref[i][0]--;
if(a[i] == 'T' && b[i] == 'C') pref[i][1]--;
if(a[i] == 'C' && b[i] == 'A') pref[i][2]--;
}
}
}
int get_distance(int x, int y) {
ar<int, 4> a = pref[y];
if(x){
for(int t=0;t<4;t++) a[t] -= pref[x-1][t];
}
if(a[0] == a[1] && a[1] == a[2]){
//~ cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<"\n";
int res = y - x + 1 - a[3];
a[0] = abs(a[0]);
assert((res - a[0] * 3) % 2 == 0);
res = (res - a[0] * 3) / 2 + a[0] * 2;
return res;
}
return -1;
}
# | 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... |