제출 #441379

#제출 시각아이디문제언어결과실행 시간메모리
441379mariowongDNA 돌연변이 (IOI21_dna)C++17
0 / 100
57 ms7024 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; int ct[100005][5],ct2[100005][5],n,ans[100005]; priority_queue <int> q[5]; char dd[5]={'A','C','T'}; void init(std::string a, std::string b) { n=a.length(); for (int i=0;i<n;i++){ for (int j=0;j<3;j++){ if (i!=0){ ct[i][j]=ct[i-1][j]; ct2[i][j]=ct2[i-1][j]; } if (a[i] == dd[j]){ ct[i][j]++; q[j].push(-i); } if (b[i] == dd[j]) ct2[i][j]++; } } for (int i=0;i<n;i++){ if (i!= 0) ans[i]=ans[i-1]; for (int j=0;j<3;j++){ if (!q[j].empty() && q[j].top() == -i){ if (dd[j] == b[i]){ q[j].pop(); break; } for (int k=0;k<3;k++){ if (b[i] == dd[k]){ q[j].pop(); q[j].push(q[k].top()); q[k].pop(); ans[i]++; } } } } } } int get_distance(int x, int y) { for (int i=0;i<3;i++){ if (x == 0){ if (ct[y][i] != ct2[y][i]) return -1; } else if (ct[y][i]-ct[x-1][i] != ct2[y][i]-ct2[x-1][i]) return -1; } if (x == 0) return ans[y]; return ans[y]-ans[x-1]; } /* string s,t; int aa,bb; int main(){ cin >> s >> t; init(s,t); for (int i=1;i<=4;i++){ cin >> aa >> bb; cout << get_distance(aa,bb) << "\n"; } }*/
#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...