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>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define xx first
#define yy second
using namespace std;
///A -> x
///T -> y
///C -> z
int n, ax[100010], ay[100010], az[100010], bx[100010], by[100010], bz[100010], xy[100010], xz[100010], yx[100010], yz[100010], zx[100010], zy[100010];
void init(std::string a, std::string b) {
n=a.size();
a='J'+a; b='J'+b;
for (int i=1; i<=n; i++)
{
if (i!=1) { ax[i]=ax[i-1]; ay[i]=ay[i-1]; az[i]=az[i-1]; }
if (a[i]=='A') ax[i]++; else if (a[i]=='T') { ay[i]++; } else az[i]++;
}
for (int i=1; i<=n; i++)
{
if (i!=1) { bx[i]=bx[i-1]; by[i]=by[i-1]; bz[i]=bz[i-1]; }
if (b[i]=='A') bx[i]++; else if (b[i]=='T') { by[i]++; } else bz[i]++;
}
for (int i=1; i<=n; i++)
{
if (i!=1) { xy[i]=xy[i-1]; xz[i]=xz[i-1]; yx[i]=yx[i-1]; yz[i]=yz[i-1]; zx[i]=zx[i-1]; zy[i]=zy[i-1]; }
if (a[i]=='A' && b[i]=='T') xy[i]++;
if (a[i]=='A' && b[i]=='C') xy[i]++;
if (a[i]=='T' && b[i]=='A') yx[i]++;
if (a[i]=='T' && b[i]=='C') yz[i]++;
if (a[i]=='C' && b[i]=='A') zx[i]++;
if (a[i]=='C' && b[i]=='T') zy[i]++;
}
}
int get_distance(int l, int r) {
ll ress=0;
int kolko1=0, kolko2=0, kolkoxy=0, kolkoxz=0, kolkoyx=0, kolkoyz=0, kolkozx=0, kolkozy=0;
l++; r++;
kolko1=ax[r]-ax[l-1];
kolko2=bx[r]-bx[l-1];
if (kolko1!=kolko2) return -1;
kolko1=ay[r]-ay[l-1];
kolko2=by[r]-by[l-1];
if (kolko1!=kolko2) return -1;
kolko1=az[r]-az[l-1];
kolko2=bz[r]-bz[l-1];
if (kolko1!=kolko2) return -1;
///imam resenje
kolkoxy=xy[r]-xy[l-1];
kolkoyx=yx[r]-yx[l-1];
kolkoxz=xz[r]-xz[l-1];
kolkozx=zx[r]-zx[l-1];
kolkoyz=yz[r]-yz[l-1];
kolkozy=zy[r]-zy[l-1];
ress+=min(kolkoxy, kolkoyx)+min(kolkoyz, kolkozy)+min(kolkoxz, kolkozx);
kolkoxy=max(kolkoxy, kolkoyx)-min(kolkoxy, kolkoyx);
kolkoyz=max(kolkoyz, kolkozy)-min(kolkoyz, kolkozy);
kolkozx=max(kolkozx, kolkoxz)-min(kolkozx, kolkoxz);
ress+=(((kolkoxy+kolkoyz+kolkozx)/3)*2);
return ress;
}
# | 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... |