Submission #482629

#TimeUsernameProblemLanguageResultExecution timeMemory
482629rc_catuntaMutating DNA (IOI21_dna)C++17
43 / 100
1565 ms3780 KiB
#include "dna.h" #include <iostream> #include <algorithm> using namespace std; string sa,sb; void init(string a, string b) { sa=a; sb=b; } 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 ct1=0,ca1=0,ct2=0,ca2=0; int cant_no_iguales=0; for(int i=0;i<a.size();i++){ if(a[i]=='T'){ ct1++; if(b[i]=='T'){ ct2++; } else{ // b[i]='A' ca2++; cant_no_iguales++; } } else{ // a[i]='A' ca1++; if(b[i]=='A'){ ca2++; } else{ // b[i]='T' ct2++; cant_no_iguales++; } } } if(ca1==ca1 and ct1==ct2) return cant_no_iguales/2; else return -1; } return 0; }

Compilation message (stderr)

dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:25:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for(int i=0;i<a.size();i++){
      |               ~^~~~~~~~~
dna.cpp:37:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i=0;i<a.size();i++){
      |               ~^~~~~~~~~
dna.cpp:59:9: warning: self-comparison always evaluates to true [-Wtautological-compare]
   59 |   if(ca1==ca1 and ct1==ct2) return cant_no_iguales/2;
      |      ~~~^~~~~
#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...