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 <string>
#include <algorithm>
static std::string a_, b_;
void init(std::string a, std::string b) {
a_ = a;
b_ = b;
}
int get_distance(int x, int y) {
int c[3] = {0,0,0};
int cc[3][3];
for (int i = 0; i <9 ; ++i) cc[i/3][i%3] = 0;
auto v = [](char c) { return c == 'A' ? 0 : c == 'C' ? 1 : 2; };
for (int i = x; i <= y; ++i) {
int v0 = v(a_[i]), v1 = v(b_[i]);
++cc[v0][v1];
++c[v0];
--c[v1];
}
if (c[0] != 0 || c[1] != 0 || c[2] != 0) return -1;
int res = 0, mv = 0;
for (int v0 = 0; v0 < 2; ++v0) {
for (int v1 = v0 + 1; v1 < 3; ++v1) {
int vlo = std::min(cc[v0][v1], cc[v1][v0]);
int vhi = std::max(cc[v0][v1], cc[v1][v0]);
res += vlo;
mv = std::max(mv, vhi - vlo);
}
}
return res + 2 * mv;
}
# | 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... |