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>
using namespace std;
using ll = long long;
ll n, m, q, k, x, y, a, b, c;
map<char, int> mpa[100001];
map<char, int> mpb[100001];
map< pair<char, char>, int > mp[100001];
void init(string a, string b) {
for (int i = 0; i < a.size(); i++) {
mp[i + 1] = mp[i];
mp[i + 1][{a[i], b[i]}]++;
mpa[i + 1] = mpa[i];
mpb[i + 1] = mpb[i];
mpa[i + 1][a[i]]++;
mpb[i + 1][b[i]]++;
}
}
int get_distance(int x, int y) {
for (auto i : {'A', 'T', 'C'}) {
// cout << i << ' ' << mpa[y + 1][i] - mpa[x][i] << ' ' << mpb[y + 1][i] - mpb[x][i] << '\n';
if (mpa[y + 1][i] - mpa[x][i] != mpb[y + 1][i] - mpb[x][i]) {
return -1;
}
}
map< pair<char, char>, int > mp1;
for (auto i : mp[y + 1]) {
mp1[i.first] = i.second - mp[x][i.first];
}
int ans = 0;
ll e;
e = min(mp1[{'A', 'T'}], mp1[{'T', 'A'}]);
ans += e;
mp1[{'A', 'T'}] -= e;
mp1[{'T', 'A'}] -= e;
e = min(mp1[{'A', 'C'}], mp1[{'C', 'A'}]);
ans += e;
mp1[{'A', 'C'}] -= e;
mp1[{'C', 'A'}] -= e;
e = min(mp1[{'C', 'T'}], mp1[{'T', 'C'}]);
ans += e;
mp1[{'C', 'T'}] -= e;
mp1[{'T', 'C'}] -= e;
e = min({mp1[{'A', 'T'}], mp1[{'T', 'C'}], mp1[{'C', 'A'}]});
ans += e * 2;
mp1[{'A', 'T'}] -= e;
mp1[{'T', 'C'}] -= e;
mp1[{'C', 'A'}] -= e;
e = min({mp1[{'T', 'A'}], mp1[{'C', 'T'}], mp1[{'A', 'C'}]});
ans += e * 2;
mp1[{'T', 'A'}] -= e;
mp1[{'C', 'T'}] -= e;
mp1[{'A', 'C'}] -= e;
return ans;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
# | 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... |