제출 #441304

#제출 시각아이디문제언어결과실행 시간메모리
441304pere_gilDNA 돌연변이 (IOI21_dna)C++17
56 / 100
116 ms19264 KiB
#include "bits/stdc++.h" #include "dna.h" using namespace std; string a,b; vector<vector<int> > leta,letb; // ac ca at ta ct tc // 0 1 2 3 4 5 vector<vector<int> > cont; int get_comb(char up, char down){ if(up=='A' && down=='C') return 0; if(up=='C' && down=='A') return 1; if(up=='A' && down=='T') return 2; if(up=='T' && down=='A') return 3; if(up=='C' && down=='T') return 4; return 5; } int get_letter(char act){ if(act=='A') return 0; if(act=='T') return 1; return 2; } void init(std::string A, std::string B) { a=A; b=B; int n=a.size(); leta.resize(n,vector<int> (3,0)); letb.resize(n,vector<int> (3,0)); cont.resize(n,vector<int> (6,0)); leta[0][get_letter(a[0])]++; letb[0][get_letter(b[0])]++; for(int i=1;i<n;i++){ for(int j=0;j<3;j++){ leta[i][j]=leta[i-1][j]; letb[i][j]=letb[i-1][j]; } leta[i][get_letter(a[i])]++; letb[i][get_letter(b[i])]++; } cont[0][get_comb(a[0],b[0])]++; for(int i=1;i<n;i++){ for(int j=0;j<6;j++) cont[i][j]=cont[i-1][j]; cont[i][get_comb(a[i],b[i])]++; } } int count_letter(bool is_a, int i, int j, int pos){ if(is_a) return (i==0) ? leta[j][pos] : leta[j][pos] - leta[i-1][pos]; return (i==0) ? letb[j][pos] : letb[j][pos] - letb[i-1][pos]; } int count_comb(int i, int j, int pos){ return (i==0) ? cont[j][pos] : cont[j][pos] - cont[i-1][pos]; } void count(int &res, int &f, int &s){ res+=f; s-=f; f=0; } int get_distance(int x, int y) { for(int i=0;i<3;i++) if(count_letter(1,x,y,i)!=count_letter(0,x,y,i)) return -1; int ac,at,ct=ac=at=0; int ca,ta,tc=ca=ta=0; ac=count_comb(x,y,0); ca=count_comb(x,y,1); at=count_comb(x,y,2); ta=count_comb(x,y,3); ct=count_comb(x,y,4); tc=count_comb(x,y,5); int res=0; (ac<ca) ? count(res,ac,ca) : count(res,ca,ac); (at<ta) ? count(res,at,ta) : count(res,ta,at); (tc<ct) ? count(res,tc,ct) : count(res,ct,tc); ac=max(ac,ca); at=max(at,ta); tc=max(tc,ct); res+=ac+at; 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...