Submission #581644

#TimeUsernameProblemLanguageResultExecution timeMemory
581644penguinhackerMutating DNA (IOI21_dna)C++17
100 / 100
50 ms8944 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=1e5; map<char, int> mp; int cnt1[mxN+1][3], cnt2[mxN+1][3][3], bad[mxN+1]; void init(string a, string b) { mp['A']=0, mp['T']=1, mp['C']=2; int n=a.size(); for (int i=0; i<n; ++i) { for (int x=0; x<3; ++x) { cnt1[i+1][x]=cnt1[i][x]+(mp[a[i]]==x)-(mp[b[i]]==x); for (int y=0; y<3; ++y) cnt2[i+1][x][y]=cnt2[i][x][y]+(mp[a[i]]==x&&mp[b[i]]==y); } bad[i+1]=bad[i]+(a[i]!=b[i]); } } int get_distance(int x, int y) { for (int i=0; i<3; ++i) if (cnt1[y+1][i]-cnt1[x][i]) return -1; int ans=0, extra=0; for (int i=0; i<3; ++i) for (int j=i+1; j<3; ++j) { int a=cnt2[y+1][i][j]-cnt2[x][i][j]; int b=cnt2[y+1][j][i]-cnt2[x][j][i]; ans+=min(a, b); extra+=max(a, b)-min(a, b); } assert(extra%3==0); return ans+extra/3*2; } /*int main() { ios::sync_with_stdio(0); cin.tie(0); init("ATACAT", "ACTATA"); cout << get_distance(1, 3) << " " << get_distance(4, 5) << " " << get_distance(3, 5); return 0; }*/
#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...