# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1060346 | tolbi | Mutating DNA (IOI21_dna) | C++17 | 20 ms | 4624 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
vector<array<int,6>> pref;
void init(std::string a, std::string b) {
pref.clear();
pref.resize(a.length()+1,array<int,6>());
for (int i = 0; i < a.length(); i++){
if (a[i]=='A' && b[i]=='C') pref[i+1][0]=1;
if (a[i]=='A' && b[i]=='T') pref[i+1][1]=1;
if (a[i]=='T' && b[i]=='A') pref[i+1][2]=1;
if (a[i]=='T' && b[i]=='C') pref[i+1][3]=1;
if (a[i]=='C' && b[i]=='A') pref[i+1][4]=1;
if (a[i]=='C' && b[i]=='T') pref[i+1][5]=1;
for (int j = 0; j < 6; j++){
pref[i+1][j]+=pref[i][j];
}
}
}
int get_distance(int x, int y) {
int ac = pref[y+1][0]-pref[x][0];
int at = pref[y+1][1]-pref[x][1];
int ta = pref[y+1][2]-pref[x][2];
int tc = pref[y+1][3]-pref[x][3];
int ca = pref[y+1][4]-pref[x][4];
int ct = pref[y+1][5]-pref[x][5];
int ans = min(ac,ca)+min(tc,ct)+min(at,ta);
if (ac>ca){
ac-=ca;
ca=0;
}
else {
ca-=ac;
ac=0;
}
if (ct>tc){
ct-=tc;
tc=0;
}
else {
tc-=ct;
ct=0;
}
if (at>ta){
at-=ta;
ta=0;
}
else {
ta-=at;
at=0;
}
if (ac>0){
if (ac!=ct || ct!=ta) return -1;
return ans+ac*2;
}
else {
if (ca!=at || tc!=ca) return -1;
return ans+ca*2;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |