제출 #441302

#제출 시각아이디문제언어결과실행 시간메모리
441302pere_gilDNA 돌연변이 (IOI21_dna)C++17
56 / 100
123 ms19212 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; vector<int> v(6); for(int i=0;i<6;i++) v[i]=count_comb(x,y,i); int res=0; for(int i=0;i<6;i+=2) (v[i]<v[i+1]) ? count(res,v[i],v[i+1]) : count(res,v[i+1],v[i]); res+=max(v[0],v[1])+max(v[2],v[3]); 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...