This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "dna.h"
VI pref[6];
/*
* AC
* CA
* AT
* TA
* CT
* TC
*/
void init(string a, string b) {
int n = a.size();
rep(k, 6) pref[k] = VI(n+1);
replr(i, 1, n) {
string cur;
cur.pb(a[i-1]);
cur.pb(b[i-1]);
if (cur == "AC") pref[0][i]++;
else if (cur == "CA") pref[1][i]++;
else if (cur == "AT") pref[2][i]++;
else if (cur == "TA") pref[3][i]++;
else if (cur == "CT") pref[4][i]++;
else if (cur == "TC") pref[5][i]++;
rep(k, 6) pref[k][i] += pref[k][i-1];
}
}
int get_distance(int l, int r) {
int cnt[6];
rep(k, 6) cnt[k] = pref[k][r+1] - pref[k][l];
int ans = 0;
int tmp;
tmp = min(cnt[0], cnt[1]);
cnt[0] -= tmp;
cnt[1] -= tmp;
ans += tmp;
tmp = min(cnt[2], cnt[3]);
cnt[2] -= tmp;
cnt[3] -= tmp;
ans += tmp;
tmp = min(cnt[4], cnt[5]);
cnt[4] -= tmp;
cnt[5] -= tmp;
ans += tmp;
int A, C, T;
A = cnt[0] + cnt[2];
C = cnt[1] + cnt[4];
T = cnt[3] + cnt[5];
if (A == C && A == T) return ans + 2*A;
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... |