Submission #708907

#TimeUsernameProblemLanguageResultExecution timeMemory
708907Essa2006Mutating DNA (IOI21_dna)C++17
100 / 100
70 ms7364 KiB
#include<bits/stdc++.h> #include "dna.h" using namespace std; #define ll long long #define endl '\n' #define FF first #define SS second #define all(a) a.begin(), a.end() #define mod (ll)(1000000007) vector<array<array<int, 3>, 3>>AA; void init(string a, string b) { int n=a.size(); AA.resize(n); for(int i=0;i<n;i++){ if(a[i]=='A') a[i]='1'; if(a[i]=='C') a[i]='3'; if(a[i]=='T') a[i]='2'; if(b[i]=='A') b[i]='1'; if(b[i]=='C') b[i]='3'; if(b[i]=='T') b[i]='2'; } for(int i=0;i<n;i++){ AA[i][a[i]-'1'][b[i]-'1']++; } for(int i=1;i<n;i++){ for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ AA[i][j][k]+=AA[i-1][j][k]; } } } } int get_distance(int x, int y) { array<array<int, 3>, 3>b; for(int j=0;j<3;j++){ for(int k=0;k<3;k++){ b[j][k]=AA[y][j][k]; b[j][k]-=(x?AA[x-1][j][k]:0); } } map<int, int>v, v2; for(int i=0;i<3;i++){ for(int j=i+1;j<3;j++){ v[i]+=b[i][j], v[j]+=b[j][i], v2[i]+=b[j][i], v2[j]+=b[i][j]; } } for(int i=0;i<3;i++){ if(v[i]!=v2[i]){ return -1; } } int ans=0, cur=0; for(int i=0;i<3;i++){ for(int j=i+1;j<3;j++){ int mn=min(b[i][j], b[j][i]); ans+=mn; b[i][j]-=mn, b[j][i]-=mn; cur+=b[i][j]+b[j][i]; } } cur/=3; cur*=2; ans+=cur; return ans; }
#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...