Submission #1048358

#TimeUsernameProblemLanguageResultExecution timeMemory
1048358amirhoseinfar1385Mutating DNA (IOI21_dna)C++17
100 / 100
38 ms9284 KiB
#include "dna.h" #include<bits/stdc++.h> using namespace std; const int maxn=100000+10; int n,alla[maxn],allb[maxn],pscnta[maxn][3],pscntb[maxn][3],pscnt[maxn][3][3]; void init(std::string a, std::string b) { n=(int)a.size(); for(int i=0;i<n;i++){ if(a[i]=='A'){ alla[i]=0; }else if(a[i]=='T'){ alla[i]=1; }else{ alla[i]=2; } if(b[i]=='A'){ allb[i]=0; }else if(b[i]=='T'){ allb[i]=1; }else{ allb[i]=2; } } for(int i=1;i<=n;i++){ for(int j=0;j<3;j++){ pscnta[i][j]+=pscnta[i-1][j]; pscntb[i][j]=pscntb[i-1][j]; } for(int j=0;j<3;j++){ for(int h=0;h<3;h++){ pscnt[i][j][h]=pscnt[i-1][j][h]; } } pscnta[i][alla[i-1]]++; pscntb[i][allb[i-1]]++; pscnt[i][alla[i-1]][allb[i-1]]++; } } int get_distance(int x, int y) { vector<int>cnta(3),cntb(3); vector<vector<int>>cnt(3,vector<int>(3)); for(int j=0;j<3;j++){ cnta[j]=pscnta[y+1][j]-pscnta[x][j]; cntb[j]=pscntb[y+1][j]-pscntb[x][j]; } for(int j=0;j<3;j++){ for(int h=0;h<3;h++){ cnt[j][h]=pscnt[y+1][j][h]-pscnt[x][j][h]; } } if(cnta!=cntb){ return -1; } int res=min(cnt[0][1],cnt[1][0])+min(cnt[0][2],cnt[2][0])+min(cnt[1][2],cnt[2][1]); cnt[0][1]=max(cnt[0][1],cnt[1][0])-min(cnt[0][1],cnt[1][0]); cnt[0][2]=max(cnt[0][2],cnt[2][0])-min(cnt[0][2],cnt[2][0]); cnt[1][2]=max(cnt[1][2],cnt[2][1])-min(cnt[1][2],cnt[2][1]); res+=((cnt[0][1]+cnt[0][2]+cnt[1][2])/3)*2; return res; }
#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...