Submission #805504

#TimeUsernameProblemLanguageResultExecution timeMemory
8055047modyMutating DNA (IOI21_dna)C++17
100 / 100
151 ms43024 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e5+10; vector<vector<vector<int>>> pre(maxn, vector<vector<int>>(3, vector<int>(3))),check(maxn, vector<vector<int>>(3, vector<int>(3))); int n; void init(string a, string b){ string s1=" " +a,s2= " " +b; n=s1.size()-1; for(int i=1; i <= n;i++){ if(s1[i]=='T') s1[i]='B'; if(s2[i]=='T') s2[i]='B'; } for(int i=1; i <= n;i++){ check[i]=check[i-1]; int a=s1[i]-'A'; int b=s2[i]-'A'; check[i][1][a]++; check[i][2][b]++; pre[i]=pre[i-1]; pre[i][a][b]++; } } int get_distance(int l, int r){ r++;l++; vector<vector<int>> curr(3, vector<int>(3)); for(int j=0; j < 3;j++){ if(check[r][1][j]-check[l-1][1][j]!=check[r][2][j]-check[l-1][2][j]){ return -1; } } for(int i=0; i < 3;i++){ for(int j=0; j < 3;j++){ curr[i][j]=pre[r][i][j]-pre[l-1][i][j]; } } int answer=0; int current=r-l+1; for(int i=0; i < 3;i++){ current-=curr[i][i]; } for(int i=0; i < 3;i++){ for(int j=i+1; j < 3;j++){ int here=min(curr[i][j],curr[j][i]); current-=2*here; answer+=here; curr[i][j]-=here; curr[j][i]-=here; } } answer+=(current/3)*2; return answer; } // int main(){ // string s1,s2; cin >> s1 >> s2; // init(s1,s2); // int q; cin >> q; // while(q--){ // int l,r; cin >> l >> r; // cout << get_distance(l,r) << endl; // } // }
#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...