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>
#define ll long long
#define vt vector
#define pb push_back
#define ar array
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
using namespace std;
/*
1. simplify
2. add new elements
3. brute force solution
4. optimize
5. start implementing
*/
// --- templates ---
// --- code ---
string a, b;
void init(string aa, string bb){
a = aa;
b = bb;
}
int get_distance(int x, int y){
map<char, int> m = {
{'A', 0},
{'T', 1},
{'C', 2}
};
vt<vt<int>> adj(3, vt<int>(3));
vt<int> c(3);
for(int i = x; i <= y; i++){
if(a[i] != b[i])
adj[m[a[i]]][m[b[i]]]++;
c[m[a[i]]]++;
c[m[b[i]]]--;
}
if(c[0] || c[1] || c[2]){
return -1;
}
int ans = 0;
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
if(adj[i][j] && adj[j][i]){
int take = min(adj[i][j], adj[j][i]);
ans += take;
adj[i][j] -= take;
adj[j][i] -= take;
}else{
for(int k = 0; k < 3; k++){
int take = min({adj[i][j], adj[j][k], adj[k][i]});
adj[i][j] -= take, adj[j][k] -= take, adj[k][i] -= take;
ans += 2 * take;
}
}
}
}
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... |