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;
const int N = 100005;
int n, cnt[3][3][N];
void init(string a, string b){
n = a.size();
for(auto &c : a)
if(c=='A') c = '0';
else if(c=='C') c = '1';
else c = '2';
for(auto &c : b)
if(c=='A') c = '0';
else if(c=='C') c = '1';
else c = '2';
a = "$"+a, b = "$"+b;
for(int i = 0; i<3; ++i)
for(int j = 0; j<3; ++j)
for(int id = 1; id<=n; ++id)
cnt[i][j][id] = cnt[i][j][id-1]+(a[id]-'0'==i && b[id]-'0'==j);
}
int get_distance(int l, int r){
++l, ++r; int ans = 0;
int tmp[3][3]; memset(tmp, 0, sizeof tmp);
for(int i = 0; i<3; ++i)
for(int j = 0; j<3; ++j)
tmp[i][j] = cnt[i][j][r]-cnt[i][j][l-1];
for(int i = 0; i<3; ++i)
for(int j = i+1; j<3; ++j){
int x = min(tmp[i][j], tmp[j][i]);
ans += x, tmp[i][j] -= x, tmp[j][i] -= x;
}
if(tmp[0][1] != tmp[1][2] || tmp[0][1] != tmp[2][0] ||
tmp[1][0] != tmp[2][1] || tmp[1][0] != tmp[0][2]) return -1;
ans += 2*(tmp[0][1]+tmp[1][0]);
return ans;
}
# | 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... |