Submission #1067371

#TimeUsernameProblemLanguageResultExecution timeMemory
1067371AlgorithmWarriorMutating DNA (IOI21_dna)C++17
100 / 100
29 ms9824 KiB
#include "dna.h" #include <bits/stdc++.h> #define MAX 100005 using namespace std; int sp[MAX][3][3]; int sp1[MAX][3]; int sp2[MAX][3]; void init(string a, string b) { int to[100]; to['A']=0; to['C']=1; to['T']=2; int n=a.size(); int i,j,k; for(i=1;i<=n;++i) { ++sp[i][to[a[i-1]]][to[b[i-1]]]; ++sp1[i][to[a[i-1]]]; ++sp2[i][to[b[i-1]]]; for(j=0;j<3;++j) sp1[i][j]+=sp1[i-1][j]; for(j=0;j<3;++j) sp2[i][j]+=sp2[i-1][j]; for(j=0;j<3;++j) for(k=0;k<3;++k) sp[i][j][k]+=sp[i-1][j][k]; } } int get_distance(int x, int y) { ++x,++y; int i,j; for(i=0;i<3;++i) if(sp1[y][i]-sp1[x-1][i]!=sp2[y][i]-sp2[x-1][i]) return -1; int nr=abs(sp[y][0][1]-sp[x-1][0][1]-sp[y][1][0]+sp[x-1][1][0]); int cnt=2*nr; for(i=0;i<3;++i) for(j=i+1;j<3;++j) cnt+=min(sp[y][i][j]-sp[x-1][i][j],sp[y][j][i]-sp[x-1][j][i]); return cnt; }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:21:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   21 |         ++sp[i][to[a[i-1]]][to[b[i-1]]];
      |                          ^
dna.cpp:21:38: warning: array subscript has type 'char' [-Wchar-subscripts]
   21 |         ++sp[i][to[a[i-1]]][to[b[i-1]]];
      |                                      ^
dna.cpp:22:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   22 |         ++sp1[i][to[a[i-1]]];
      |                           ^
dna.cpp:23:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   23 |         ++sp2[i][to[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...