제출 #440030

#제출 시각아이디문제언어결과실행 시간메모리
440030algorithm16DNA 돌연변이 (IOI21_dna)C++17
100 / 100
67 ms8752 KiB
#include "dna.h" #include<iostream> #include<string> #include<algorithm> using namespace std; string a1,b1,s="ACT"; int n,cnt[3][2][100005],p[3][3][100005]; int get_cnt(int ind1,int ind2,int l,int r) { if(!l) return cnt[ind1][ind2][r]; return cnt[ind1][ind2][r]-cnt[ind1][ind2][l-1]; } int get_p(int ind1,int ind2,int l,int r) { if(!l) return p[ind1][ind2][r]; return p[ind1][ind2][r]-p[ind1][ind2][l-1]; } void init(std::string a, std::string b) { n=a.size(); for(int i=0;i<n;i++) { for(int j=0;j<3;j++) { if(a[i]==s[j]) cnt[j][0][i]=1; if(b[i]==s[j]) cnt[j][1][i]=1; } for(int j=0;j<3;j++) { for(int k=0;k<2;k++) { if(i) cnt[j][k][i]+=cnt[j][k][i-1]; } } for(int j=0;j<3;j++) { for(int k=0;k<3;k++) { if(j!=k && a[i]==s[j] && b[i]==s[k]) p[j][k][i]=1; } } for(int j=0;j<3;j++) { for(int k=0;k<3;k++) { if(i) p[j][k][i]+=p[j][k][i-1]; } } } /*for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { cout << p[i][j][n-1] << " "; } } cout << "\n";*/ /*for(int i=0;i<3;i++) { for(int j=0;j<n;j++) { cout << cnt[i][0][j] << " "; } cout << "\n"; }*/ } int get_distance(int x, int y) { int diffa=get_cnt(0,0,x,y)-get_cnt(0,1,x,y); int diffc=get_cnt(1,0,x,y)-get_cnt(1,1,x,y); int difft=get_cnt(2,0,x,y)-get_cnt(2,1,x,y); //cout << x << " " << y << " " << diffa << " " << diffc << " " << difft << "\n"; if(diffa!=0 || diffc!=0 || difft!=0) return -1; int l=0,ret=0; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { l+=get_p(i,j,x,y); } } //cout << l << "\n"; for(int i=0;i<3;i++) { for(int j=i+1;j<3;j++) { int sum=min(get_p(i,j,x,y),get_p(j,i,x,y)); ret+=sum; l-=sum*2; } } return ret+(l/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...