Submission #483148

#TimeUsernameProblemLanguageResultExecution timeMemory
483148rc_catuntaMutating DNA (IOI21_dna)C++17
56 / 100
34 ms6072 KiB
#include "dna.h" #include <iostream> #include <algorithm> #include <vector> using namespace std; string sa,sb; vector<int>ct1,ca1,ct2,ca2,dif; void init(string a, string b) { sa=a; sb=b; int tam = a.size(); ct1.assign(tam,0); ca1.assign(tam,0); ct2.assign(tam,0); ca2.assign(tam,0); dif.assign(tam,0); for(int i=0;i<tam;i++){ if(i>0){ ct1[i]=ct1[i-1]; ca1[i]=ca1[i-1]; ct2[i]=ct2[i-1]; ca2[i]=ca2[i-1]; dif[i]=dif[i-1]; } if(a[i]=='T') ct1[i]++; if(a[i]=='A') ca1[i]++; if(b[i]=='T') ct2[i]++; if(b[i]=='A') ca2[i]++; if(a[i]!=b[i]) dif[i]++; } } int get_distance(int x, int y) { if(y-x<=2){ string a=sa.substr(x,y-x+1); string b=sb.substr(x,y-x+1); if(a==b) return 0; string ca = a; string cb = b; sort(ca.begin(),ca.end()); sort(cb.begin(),cb.end()); if(ca != cb) return -1; int cm = 0; for(int i=0;i<a.size();i++){ if(a[i]==b[i]) cm++; } if(a.size()==3) return 2-cm; if(a.size()==2) return 1-cm; } else{ //string a=sa.substr(x,y-x+1); //string b=sb.substr(x,y-x+1); //if(a==b) return 0; int cot1=0,coa1=0,cot2=0,coa2=0; int cant_no_iguales=0; if(x>0){ cot1 = ct1[y]-ct1[x-1]; coa1 = ca1[y]-ca1[x-1]; cot2 = ct2[y]-ct2[x-1]; coa2 = ca2[y]-ca2[x-1]; cant_no_iguales = dif[y]-dif[x-1]; } else{ cot1 = ct1[y]; coa1 = ca1[y]; cot2 = ct2[y]; coa2 = ca2[y]; cant_no_iguales = dif[y]; } if(coa1==coa1 and cot1==cot2) return cant_no_iguales/2; else return -1; } return 0; }

Compilation message (stderr)

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:47:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i=0;i<a.size();i++){
      |               ~^~~~~~~~~
dna.cpp:74:10: warning: self-comparison always evaluates to true [-Wtautological-compare]
   74 |   if(coa1==coa1 and cot1==cot2) return cant_no_iguales/2;
      |      ~~~~^~~~~~
dna.cpp:57:28: warning: variable 'coa2' set but not used [-Wunused-but-set-variable]
   57 |   int cot1=0,coa1=0,cot2=0,coa2=0;
      |                            ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...