# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
580270 | rc_catunta | Mutating DNA (IOI21_dna) | C++17 | 1564 ms | 2900 KiB |
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"
#include <algorithm>
#include <vector>
using namespace std;
string sa, sb;
vector<int> acum;
void init(string a, string b) {
sa = a;
sb = b;
// Construimos la tabla de acumuladas
acum.assign(a.size(),0);
for(int i=0;i<a.size();i++){
if(a[i]!=b[i]) acum[i]++;
if(i>0) acum[i]+=acum[i-1];
}
}
bool posible_transformar(string a, string b){
string ca=a,cb=b;
sort(ca.begin(),ca.end());
sort(cb.begin(),cb.end());
return ca==cb;
}
int get_distance(int x, int y) {
string a = sa.substr(x,y-x+1);
string b = sb.substr(x,y-x+1);
// SUBTASK 1
if(y-x<=2){
if(a==b) return 0;
if(posible_transformar(a,b)){
if(y-x==1) return 1;
// Contar letras igual
int cont = 0;
for(int i=0;i<a.size();i++){
if(a[i]==b[i]) cont++;
}
if(cont==1) return 1;
else return 2;
}
else return -1;
}
// SUBTASK 2 Y 3
if(posible_transformar(a,b)){
int cont_des = acum[y];
if(x>0) cont_des -= acum[x-1];
return(cont_des/2);
}
else return -1;
}
Compilation message (stderr)
# | 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... |