Submission #585371

#TimeUsernameProblemLanguageResultExecution timeMemory
585371krit3379Mutating DNA (IOI21_dna)C++17
21 / 100
46 ms8972 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") int cnt[2][3][N],dp[9][N]; map<char,int> mp; void init(string a, string b){ int i,j; mp['A']=0; mp['C']=1; mp['T']=2; a=' '+a; b=' '+b; for(i=1;i<a.size();i++){ for(j=0;j<3;j++)cnt[0][j][i]=cnt[0][j][i-1]; cnt[0][mp[a[i]]][i]++; } for(i=1;i<b.size();i++){ for(j=0;j<3;j++)cnt[1][j][i]=cnt[1][j][i-1]; cnt[1][mp[b[i]]][i]++; } for(i=1;i<a.size();i++){ for(j=0;j<9;j++)dp[j][i]=dp[j][i-1]; dp[mp[a[i]]*3+mp[b[i]]][i]++; } } int get_distance(int x,int y){ int i,j,a,b,mi,sum=0,ans=0; x++,y++; for(i=0;i<3;i++)if(cnt[0][i][y]-cnt[0][i][x-1]!=cnt[1][i][y]-cnt[1][i][x-1])return -1; for(i=0;i<3;i++)for(j=i+1;j<3;j++){ a=i*3+j; b=j*3+i; mi=min(dp[a][y]-dp[a][x-1],dp[b][y]-dp[b][x-1]); ans+=mi; sum+=dp[a][y]-dp[a][x-1]+dp[b][y]-dp[b][x-1]; } return ans+(sum-2*mi)/3*2; }

Compilation message (stderr)

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