Submission #678166

#TimeUsernameProblemLanguageResultExecution timeMemory
678166MuhammetaliMutating DNA (IOI21_dna)C++17
100 / 100
41 ms8968 KiB
#include "dna.h" #include<bits/stdc++.h> using namespace std; string s,ss; int dna[2][3][100001],jem[100001],res[100001][6]; map<char,int>mp; void init(string s,string ss) { mp['A']=0; mp['T']=1; mp['C']=2; dna[0][mp[s[0]]][0]=1; dna[1][mp[ss[0]]][0]=1; if(s[0]==ss[0])jem[0]=1; for(int i=1;i<s.size();i++){ jem[i]=jem[i-1]; if(s[i]==ss[i])jem[i]++; for(int j=0;j<3;j++){ dna[0][j][i]=dna[0][j][i-1]; dna[1][j][i]=dna[1][j][i-1]; } dna[0][mp[s[i]]][i]++; dna[1][mp[ss[i]]][i]++; } for(int i=0;i<s.size();i++){ if(i)for(int j=0;j<6;j++)res[i][j]=res[i-1][j]; if(s[i]=='A'){ if(ss[i]=='T'){ res[i][0]++; } else if(ss[i]=='C'){ res[i][2]++; } }else if(s[i]=='T'){ if(ss[i]=='A'){ res[i][1]++; }else if(ss[i]=='C'){ res[i][5]++; } }else if(s[i]=='C'){ if(ss[i]=='A'){ res[i][3]++; }else if(ss[i]=='T'){ res[i][4]++; } } } } int get_distance(int x,int y) { int cnt=jem[y]-(x-1<0?0:jem[x-1]); int a1=dna[0][0][y]-(x-1<0?0:dna[0][0][x-1]); int t1=dna[0][1][y]-(x-1<0?0:dna[0][1][x-1]); int c1=dna[0][2][y]-(x-1<0?0:dna[0][2][x-1]); int a2=dna[1][0][y]-(x-1<0?0:dna[1][0][x-1]); int t2=dna[1][1][y]-(x-1<0?0:dna[1][1][x-1]); int c2=dna[1][2][y]-(x-1<0?0:dna[1][2][x-1]); int len=y-x+1; if(a1!=a2 || t1!=t2 || c1!=c2)return -1; int at=min(res[y][0]-(x-1<0?0:res[x-1][0]),res[y][1]-(x-1<0?0:res[x-1][1])); int ac=min(res[y][2]-(x-1<0?0:res[x-1][2]),res[y][3]-(x-1<0?0:res[x-1][3])); int tc=min(res[y][4]-(x-1<0?0:res[x-1][4]),res[y][5]-(x-1<0?0:res[x-1][5])); int atc=len-(cnt+(at*2)+(ac*2)+(tc*2)); return (at+ac+tc+((atc/3)*2)); }

Compilation message (stderr)

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