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;
string s3, s4;
void init(string s, string s2){
s3 = s, s4 = s2;
}
int get_distance(int x, int y){
// atacat
// actata
string a = "", b = "";
for(int i = x; i <= y; ++i)
a += s3[i], b += s4[i];
// cout << a << " " << b << "\n";
int n = (int)a.size();
int sm = 0, sm2 = 0, sm3 = 0;
for(int i = 0; i < n; ++i){
if(a[i] == 'A')
sm++;
if(b[i] == 'A')
sm--;
if(a[i] == 'C')
sm2++;
if(b[i] == 'C')
sm2--;
if(a[i] == 'T')
sm3++;
if(b[i] == 'T')
sm3--;
}
if(sm or sm2 or sm3)
return -1;
// cout << a << " " << b << "\n";
// printf("%d %d %d %d\n", sm, sm2, sm3, n);
// O(q*m^2)
// tac
// cta
int answer = 0;
for(int i = 0; i < n; ++i){
if(a[i] == b[i])
continue;
for(int j = i+1; j < n; ++j)
if(a[j] == b[i] and b[j] == a[i]){
answer++;
swap(a[i], a[j]);
}
}
for(int i = 0; i < n; ++i){
if(a[i] == b[i])
continue;
assert(a[i] != b[i]);
for(int j = i+1; j < n; ++j)
if(a[j] == b[i]){
answer++;
swap(a[i], a[j]);
}
}
return answer;
}
# | 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... |