# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499833 | sazid_alam | Mutating DNA (IOI21_dna) | C++17 | 48 ms | 9708 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;
int tot[100005][3][2], bad[100005][3][3];
void init(string u, string v) {
for(int i = 0; i < u.size(); i++){
for(int j = 0; j < 3; j++){
for(int k = 0; k < 3; k++){
bad[i + 1][j][k] += bad[i][j][k];
}
}
if(u[i] != v[i]){
if(u[i] == 'A' && v[i] == 'C') bad[i + 1][0][1]++;
if(u[i] == 'A' && v[i] == 'T') bad[i + 1][0][2]++;
if(u[i] == 'C' && v[i] == 'A') bad[i + 1][1][0]++;
if(u[i] == 'C' && v[i] == 'T') bad[i + 1][1][2]++;
if(u[i] == 'T' && v[i] == 'A') bad[i + 1][2][0]++;
if(u[i] == 'T' && v[i] == 'C') bad[i + 1][2][1]++;
}
if(u[i] == 'A') tot[i + 1][0][0]++;
if(v[i] == 'A') tot[i + 1][0][1]++;
if(u[i] == 'C') tot[i + 1][1][0]++;
if(v[i] == 'C') tot[i + 1][1][1]++;
if(u[i] == 'T') tot[i + 1][2][0]++;
if(v[i] == 'T') tot[i + 1][2][1]++;
for(int j = 0; j < 3; j++){
tot[i + 1][j][0] += tot[i][j][0];
tot[i + 1][j][1] += tot[i][j][1];
}
}
}
int get_distance(int x, int y) {
for(int j = 0; j < 3; j++){
if(tot[y + 1][j][0] - tot[x][j][0] != tot[y + 1][j][1] - tot[x][j][1]) return -1;
}
int ans = 0, extra = 1000000;
bool done[3][3] = {0};
for(int j = 0; j < 3; j++){
for(int k = 0; k < 3; k++){
if(done[j][k] || done[k][j] || j == k) continue;
int ch = min(bad[y + 1][j][k] - bad[x][j][k], bad[y + 1][k][j] - bad[x][k][j]);
int hc = max(bad[y + 1][j][k] - bad[x][j][k], bad[y + 1][k][j] - bad[x][k][j]);
ans += ch;
extra = min(extra, hc - ch);
done[j][k] = true;
}
}
return ans + extra * 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... |