Submission #585325

#TimeUsernameProblemLanguageResultExecution timeMemory
585325cfalasMutating DNA (IOI21_dna)C++17
100 / 100
46 ms10220 KiB
#include "dna.h" #include<bits/stdc++.h> using namespace std; int m[3][3][200000]; int x[256]; int cc[200000]; int Aa[200000]; int Ta[200000]; int Ca[200000]; int Ab[200000]; int Tb[200000]; int Cb[200000]; void init(std::string a, std::string b) { x['A'] = 0; x['T'] = 1; x['C'] = 2; int n = a.size(); for(int i=0;i<n;i++){ Aa[i+1] = Aa[i] + (a[i]=='A'); Ta[i+1] = Ta[i] + (a[i]=='T'); Ca[i+1] = Ca[i] + (a[i]=='C'); Ab[i+1] = Ab[i] + (b[i]=='A'); Tb[i+1] = Tb[i] + (b[i]=='T'); Cb[i+1] = Cb[i] + (b[i]=='C'); for(int j=0;j<3;j++){ for(int k=0;k<3;k++) m[j][k][i+1] = m[j][k][i]; } m[x[a[i]]][x[b[i]]][i+1] = m[x[a[i]]][x[b[i]]][i] + 1; cc[i+1] = cc[i] + (a[i]==b[i]); //cout<<Aa[i+1]<<" "<<Ta[i+1]<<" "<<Ca[i+1]<<" "<<cc[i+1]<<endl; } } int get_distance(int x, int y) { x++, y++; if(Aa[y]-Aa[x-1] != Ab[y]-Ab[x-1]) return -1; if(Ta[y]-Ta[x-1] != Tb[y]-Tb[x-1]) return -1; if(Ca[y]-Ca[x-1] != Cb[y]-Cb[x-1]) return -1; int tot=0; int tot2=0; for(int i=0;i<3;i++){ for(int j=i+1;j<3;j++){ tot += abs((m[i][j][y]-m[i][j][x-1]) - (m[j][i][y]-m[j][i][x-1])); tot2 += min((m[i][j][y]-m[i][j][x-1]), (m[j][i][y]-m[j][i][x-1])); } } //cout<<tot2<<" "<<tot<<endl; return tot/3 * 2 + tot2; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:31:11: warning: array subscript has type 'char' [-Wchar-subscripts]
   31 |   m[x[a[i]]][x[b[i]]][i+1] = m[x[a[i]]][x[b[i]]][i] + 1;
      |           ^
dna.cpp:31:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   31 |   m[x[a[i]]][x[b[i]]][i+1] = m[x[a[i]]][x[b[i]]][i] + 1;
      |                    ^
dna.cpp:31:38: warning: array subscript has type 'char' [-Wchar-subscripts]
   31 |   m[x[a[i]]][x[b[i]]][i+1] = m[x[a[i]]][x[b[i]]][i] + 1;
      |                                      ^
dna.cpp:31:47: warning: array subscript has type 'char' [-Wchar-subscripts]
   31 |   m[x[a[i]]][x[b[i]]][i+1] = m[x[a[i]]][x[b[i]]][i] + 1;
      |                                               ^
#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...