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"
#include "dna.h"
using namespace std;
const int sz = 1e5 + 5;
int pa[sz], pt[sz];
int n;
string s, t;
void init(string a, string b) {
n = a.size();
s = ' ' + a, t = ' ' + b;
for (int i = 1; i <= n; i ++) {
pa[i] = pa[i - 1], pt[i] = pt[i - 1];
if ('A' == s[i] && 'T' == t[i]) {
pa[i] ++;
} else if ('T' == s[i] && 'A' == t[i]) {
pt[i] ++;
}
}
}
int get_distance(int x, int y) {
x ++, y ++;
int d = y - x + 1;
if (d <= 3) {
if (1 == d) {
if (s[x] == t[x]) return 0;
return -1;
} else if (2 == d) {
if (s[x] == t[x] && s[y] == t[y]) return 0;
if (s[x] == t[y] && s[y] == t[x]) return 1;
return -1;
} else {
if (s.substr(x, d) == t.substr(x, d)) return 0;
int d = 3 * x + 3;
for (int i = x; i < y; i ++) {
for (int j = x + 1; j <= y; j ++) {
int e = d - i - j;
if (s[i] == t[j] && s[j] == t[i] && s[e] == t[e]) return 1;
}
}
map<char, int> cna, cnt;
for (int i = x; i <= y; i ++) {
cna[s[i]] ++, cnt[t[i]] ++;
}
if (cna['A'] != cnt['A'] || cna['C'] != cnt['C'] || cna['T'] != cnt['T']) return -1;
return 2;
}
} else {
int pac = pa[y] - pa[x - 1];
int ptc = pt[y] - pt[x - 1];
if (pac != ptc) {
return -1;
} else {
return pac;
}
}
}
# | 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... |