제출 #1339878

#제출 시각아이디문제언어결과실행 시간메모리
1339878ElayV13DNA 돌연변이 (IOI21_dna)C++20
71 / 100
1594 ms4916 KiB
#include "dna.h"
#include "bits/stdc++.h"
using namespace std;

string A,B;

int pa[3][100001];
int pb[3][100001];

void init(string a,string b)
{
      A=a;
      B=b;
      int n=a.size();
      pa[0][0]=(a[0]=='A');
      pa[1][0]=(a[0]=='C');
      pa[2][0]=(a[0]=='T');
      for(int i=1;i<n;i++)
      {
            pa[0][i]=pa[0][i-1]+(a[i]=='A');
            pa[1][i]=pa[1][i-1]+(a[i]=='C');
            pa[2][i]=pa[2][i-1]+(a[i]=='T');
      }
      pb[0][0]=(b[0]=='A');
      pb[1][0]=(b[0]=='C');
      pb[2][0]=(b[0]=='T');
      for(int i=1;i<n;i++)
      {
            pb[0][i]=pb[0][i-1]+(b[i]=='A');
            pb[1][i]=pb[1][i-1]+(b[i]=='C');
            pb[2][i]=pb[2][i-1]+(b[i]=='T');
      }
}

int get(int l,int r,int x,int t){
      if(t==0){
            if(l==0) return pa[x][r];
            else return pa[x][r]-pa[x][l-1];
      }
      else{
            if(l==0) return pb[x][r];
            else return pb[x][r]-pb[x][l-1];
      }
}

int get_distance(int x,int y)
{
      vector<int>ca(3),cb(3);
      ca[0]=get(x,y,0,0);
      ca[1]=get(x,y,1,0);
      ca[2]=get(x,y,2,0);
      cb[0]=get(x,y,0,1);
      cb[1]=get(x,y,1,1);
      cb[2]=get(x,y,2,1);
      for(int i=0;i<3;i++) if(ca[i]!=cb[i]) return -1;
      int AC=0;
      int CA=0;
      int AT=0;
      int TA=0;
      int CT=0;
      int TC=0;
      for(int i=x;i<=y;i++){
            if(A[i]==B[i]) continue;
            if(B[i]=='A'&&A[i]=='C') AC++;
            if(B[i]=='C'&&A[i]=='A') CA++;
            if(B[i]=='A'&&A[i]=='T') AT++;
            if(B[i]=='T'&&A[i]=='A') TA++;
            if(B[i]=='C'&&A[i]=='T') CT++;
            if(B[i]=='T'&&A[i]=='C') TC++;
      }
      int res=0;
      int s1=min(AC,CA);
      int s2=min(AT,TA);
      int s3=min(CT,TC);
      res+=s1;
      res+=s2;
      res+=s3;
      AC-=s1;
      CA-=s1;
      AT-=s2;
      TA-=s2;
      CT-=s3;
      TC-=s3;
      int add=(AC+CA+AT+TA+CT+TC);
      return (res+((add/3)*2));
}
#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...