Submission #530882

#TimeUsernameProblemLanguageResultExecution timeMemory
530882knon0501Mutating DNA (IOI21_dna)C++17
100 / 100
61 ms9940 KiB
#include<bits/stdc++.h> using namespace std; int sa[100005][3]; int sb[100005][3]; int e[100005][3][3]; int c[200]; int n; string a,b; void init(std::string aa, std::string bb) { a=aa; b=bb; n=a.length(); c['A']=0; c['T']=1; c['C']=2; for(int i=1 ; i<=n ; i++){ sa[i][0]=sa[i-1][0]; sb[i][0]=sb[i-1][0]; sa[i][1]=sa[i-1][1]; sb[i][1]=sb[i-1][1]; sa[i][2]=sa[i-1][2]; sb[i][2]=sb[i-1][2]; sa[i][c[a[i-1]]]++; sb[i][c[b[i-1]]]++; for(int j=0 ; j<3 ; j++) for(int k=0 ; k<3 ; k++) e[i][j][k]=e[i-1][j][k]; e[i][c[a[i-1]]][c[b[i-1]]]++; } } int get_distance(int x, int y) { x++; y++; for(int i=0 ; i<3 ; i++) if(sa[y][i]-sa[x-1][i]!=sb[y][i]-sb[x-1][i])return -1; int d[3][3]={0,}; for(int i=0 ; i<3 ; i++) for(int j=0 ; j<3 ; j++) d[i][j]=e[y][i][j]-e[x-1][i][j]; int ans=0; int cnt=0; for(int i=0 ; i<3 ; i++){ for(int j=0 ; j<3 ; j++){ int k=min(d[i][j],d[j][i]); d[i][j]-=k; if(i!=j) d[j][i]-=k; if(i!=j) ans+=k; cnt+=d[i][j]; } } return ans+cnt*2/3; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:24:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   24 |   sa[i][c[a[i-1]]]++;
      |                 ^
dna.cpp:25:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   25 |   sb[i][c[b[i-1]]]++;
      |                 ^
dna.cpp:29:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   29 |   e[i][c[a[i-1]]][c[b[i-1]]]++;
      |                ^
dna.cpp:29:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   29 |   e[i][c[a[i-1]]][c[b[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...