Submission #580274

#TimeUsernameProblemLanguageResultExecution timeMemory
580274rc_catuntaMutating DNA (IOI21_dna)C++17
56 / 100
761 ms6156 KiB
#include "dna.h" #include <algorithm> #include <vector> using namespace std; string sa, sb; vector<int> acumd,acuma1,acuma2,acumt1,acumt2; void init(string a, string b) { sa = a; sb = b; // Construimos la tabla de acumuladas acumd.assign(a.size(),0); acuma1.assign(a.size(),0); acumt1.assign(a.size(),0); acuma2.assign(a.size(),0); acumt2.assign(a.size(),0); for(int i=0;i<a.size();i++){ // Acum d if(a[i]!=b[i]) acumd[i]++; if(i>0) acumd[i]+=acumd[i-1]; // Acum A para el string 1 if(a[i]=='A') acuma1[i]++; if(i>0) acuma1[i]+=acuma1[i-1]; // Acum A para el string 2 if(b[i]=='A') acuma2[i]++; if(i>0) acuma2[i]+=acuma2[i-1]; // Acum T para el string 1 if(a[i]=='T') acumt1[i]++; if(i>0) acumt1[i]+=acumt1[i-1]; // Acum T para el string 2 if(b[i]=='T') acumt2[i]++; if(i>0) acumt2[i]+=acumt2[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 // Se puede? int cont_a1 = acuma1[y]; int cont_a2 = acuma2[y]; int cont_t1 = acumt1[y]; int cont_t2 = acumt2[y]; int cont_des = acumd[y]; if(x>0){ cont_des -= acumd[x-1]; cont_a1 -= acuma1[x-1]; cont_a2 -= acuma2[x-1]; cont_t1 -= acumt1[x-1]; cont_t2 -= acumt2[x-1]; } if(cont_a1 == cont_a2 and cont_t1 == cont_t2){ if(cont_des%2 == 0){ return cont_des/2; } else return -1; } else return -1; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:18:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i=0;i<a.size();i++){
      |              ~^~~~~~~~~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:55:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |    for(int i=0;i<a.size();i++){
      |                ~^~~~~~~~~
#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...