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 int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>
using namespace std;
const int MAXN = 1e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;
vector<vector<int>> pref(6, vector<int>(MAXN));
void init(std::string a, std::string b) {
int n = a.size();
for(int i=0; i<n; i++)
{
if(a[i] == 'A' && b[i]=='T')pref[0][i+1] = 1;
else if(a[i] == 'A' && b[i]=='C')pref[1][i+1] = 1;
else if(a[i] == 'T' && b[i]=='A')pref[2][i+1] = 1;
else if(a[i] == 'T' && b[i]=='C')pref[3][i+1] = 1;
else if(a[i] == 'C' && b[i]=='A')pref[4][i+1] = 1;
else if(a[i] == 'C' && b[i]=='T')pref[5][i+1] = 1;
pref[0][i+1] += pref[0][i];
pref[1][i+1] += pref[1][i];
pref[2][i+1] += pref[2][i];
pref[3][i+1] += pref[3][i];
pref[4][i+1] += pref[4][i];
pref[5][i+1] += pref[5][i];
}
}
int get_distance(int x, int y) {
vector<int> niz(6);
niz[0] = pref[0][y+1] - pref[0][x];
niz[1] = pref[1][y+1] - pref[1][x];
niz[2] = pref[2][y+1] - pref[2][x];
niz[3] = pref[3][y+1] - pref[3][x];
niz[4] = pref[4][y+1] - pref[4][x];
niz[5] = pref[5][y+1] - pref[5][x];
if(niz[0] + niz[1] == niz[2]+niz[4] && niz[2] + niz[3] == niz[0] + niz[5] && niz[4] + niz[5] == niz[1] + niz[3])
{
int atmin = min(niz[0], niz[2]);
int atmax = max(niz[0], niz[2]);
int acmin = min(niz[1], niz[4]);
int acmax = max(niz[1], niz[4]);
int tcmin = min(niz[3], niz[5]);
int tcmax = max(niz[3], niz[5]);
int rez = atmin + acmin + tcmin;
atmax -= atmin;
acmax -= acmin;
tcmax -= tcmin;
rez+= max({atmax, acmax, tcmax})*2;
return rez;
}
else return -1;
}
/*
6 3
ATACAT
ACTATA
1 3
4 5
3 5
*/
# | 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... |