Submission #1058800

#TimeUsernameProblemLanguageResultExecution timeMemory
10588000pt1mus23Mutating DNA (IOI21_dna)C++17
100 / 100
101 ms6008 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; #define ins insert #define pb push_back #define pii pair<int, int> #define all(x) x.begin(),x.end() #define hash z0hashp #define div z0dvp map<string,vector<int>> pref; /* AC CA TA AT CT TC */ void init(string a, string b) { int n= a.size(); vector<string> lst={"AC","CA","AT","TA","CT","TC"}; for(auto v:lst){ pref[v].resize(n+1,0); } for(int i=0;i<n;i++){ if(a[i]!=b[i]){ string s=""; s+=a[i]; s+=b[i]; pref[s][i]++; } for(auto v:lst){ pref[v][i]+=(i?pref[v][i-1]:0); } } } int get_distance(int x, int y) { int ac=pref["AC"][y] - (x?pref["AC"][x-1]:0); int ca=pref["CA"][y] - (x?pref["CA"][x-1]:0); int at=pref["AT"][y] - (x?pref["AT"][x-1]:0); int ta=pref["TA"][y] - (x?pref["TA"][x-1]:0); int ct=pref["CT"][y] - (x?pref["CT"][x-1]:0); int tc=pref["TC"][y] - (x?pref["TC"][x-1]:0); vector<pair<string,int>> lst; int ans=min(ac,ca) + min(at,ta) + min(ct,tc); int a = max(ac,ca) - min(ac,ca); int b = max(ta,at) - min(ta,at); int c = max(ct,tc) - min(ct,tc); /* AC CA AT TA CT TC */ if(min({a,b,c})!=max({a,b,c})){ return -1; } map<string,int> var; map<string,int> lazim; if(ac>ca){ var["A"]+=a; lazim["C"]+=a; } else if(ca>ac){ var["C"]+=a; lazim["A"]+=a; } if(ta>at){ var["T"]+=b; lazim["A"]+=b; } else if(ta<at){ var["A"]+=b; lazim["T"]+=b; } if(ct<tc){ var["T"]+=c; lazim["C"]+=c; } else if(ct>tc){ var["C"]+=c; lazim["T"]+=c; } for(auto v:lazim){ if(var[v.first]!=v.second){ return -1; } var[v.first]=0; } for(auto v:var){ if(v.second){ return -1; } } ans+=a*2; 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...