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 "dna.h"
using namespace std;
#include <vector>
#include <iostream>
vector<int> ca;
vector<int> ac;
vector<int> ct;
vector<int> tc;
vector<int> ta;
vector<int> at;
void init(std::string a, std::string b) {
ca.resize(a.size()+1,0);
ct.resize(a.size()+1,0);
ac.resize(a.size()+1,0);
at.resize(a.size()+1,0);
ta.resize(a.size()+1,0);
tc.resize(a.size()+1,0);
for (int i=0;i<a.size();i++){
ca[i+1]=ca[i];
ct[i+1]=ct[i];
at[i+1]=at[i];
ac[i+1]=ac[i];
ta[i+1]=ta[i];
tc[i+1]=tc[i];
if (a[i]=='C'){
if (b[i]=='A'){
ca[i+1]++;
}else if (b[i]=='T'){
ct[i+1]++;
}
}else if (a[i]=='T'){
if (b[i]=='A'){
ta[i+1]++;
}else if (b[i]=='C'){
tc[i+1]++;
}
}else{
if (b[i]=='C'){
ac[i+1]++;
}else if (b[i]=='T'){
at[i+1]++;
}
}
}
// for (int i:ac){cerr<<i;}cerr<<'\n';
// for (int i:at){cerr<<i;}cerr<<'\n';
// for (int i:ca){cerr<<i;}cerr<<'\n';
// for (int i:ct){cerr<<i;}cerr<<'\n';
// for (int i:ta){cerr<<i;}cerr<<'\n';
// for (int i:tc){cerr<<i;}cerr<<'\n';
}
int get_distance(int x, int y) {
y++;
if (ca[y]-ca[x]+ct[y]-ct[x]!=ac[y]-ac[x]+tc[y]-tc[x]){
return -1;
}
if (ta[y]-ta[x]+tc[y]-tc[x]!=at[y]-at[x]+ct[y]-ct[x]){
return -1;
}
if (ac[y]-ac[x]+at[y]-at[x]!=ca[y]-ca[x]+ta[y]-ta[x]){
return -1;
}
int z=ca[y]-ca[x]+ct[y]-ct[x]+ta[y]-ta[x]+tc[y]-tc[x]+ac[y]-ac[x]+at[y]-at[x];
int t=ca[y]-ca[x]-min(ca[y]-ca[x],ac[y]-ac[x]);
t=max(t,ac[y]-ac[x]-min(ca[y]-ca[x],ac[y]-ac[x]));
t=max(t,at[y]-at[x]-min(ta[y]-ta[x],at[y]-at[x]));
t=max(t,ta[y]-ta[x]-min(ta[y]-ta[x],at[y]-at[x]));
t=max(t,tc[y]-tc[x]-min(tc[y]-tc[x],ct[y]-ct[x]));
t=max(t,ct[y]-ct[x]-min(tc[y]-tc[x],ct[y]-ct[x]));
z-=t;
z-=min(ca[y]-ca[x],ac[y]-ac[x]);
z-=min(ta[y]-ta[x],at[y]-at[x]);
z-=min(tc[y]-tc[x],ct[y]-ct[x]);
return z;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | 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... |