# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
527671 | vivaan_gupta | Mutating DNA (IOI21_dna) | C++17 | 41 ms | 9032 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;
const int N = 1e5 + 5;
map<char,int> mp;
string A, B;
int cnt[N][3];
int cnt2[N][3];
int bad[N];
int all[N][3][3], all2[N][3][3];
void init(std::string a, std::string b) {
A = a, B = b;
mp['A'] = 0;
mp['C'] = 1;
mp['T'] = 1;
for(int i = 0;i < a.size();i++){
int tmp = mp[a[i]];
int gg = (a[i] != b[i]);
cnt[i][tmp] ++;
bad[i] = gg;
if(i > 0){
bad[i] += bad[i-1];
for(int j = 0;j < 3;j++){
cnt[i][j] += cnt[i-1][j];
}
}
int tmp2 = mp[b[i]];
cnt2[i][tmp2] ++;
if(i > 0){
for(int j = 0;j < 3;j++){
cnt2[i][j] += cnt2[i-1][j];
}
}
all[i][tmp][tmp2] ++;
if(i > 0){
for(int j = 0;j< 3;j++){
for(int k =0;k<3;k++){
all[i][j][k] += all[i-1][j][k];
}
}
}
}
return;
}
int get_distance(int x, int y) {
bool ok = 1;
for(int i = 0;i < 3;i++){
int sum = cnt[y][i];
if(x > 0) sum -= cnt[x - 1][i];
int sum2 = cnt2[y][i];
if(x > 0) sum2 -= cnt2[x - 1][i];
ok &= (sum == sum2);
}
if(!ok) return -1;
int sum = bad[y];
if(x > 0) sum -= bad[x-1];
int left = sum;
sum = 0;
for(int a = 0;a < 3;a++){
for(int b = a + 1;b < 3;b++){
// a b
// b a
int tmp1 = all[y][a][b];
int tmp2 = all[y][b][a];
if(x > 0){
tmp1 -= all[x - 1][a][b];
tmp2 -= all[x - 1][b][a];
}
left -= min(tmp1, tmp2) * 2;
sum += min(tmp1, tmp2);
}
}
return sum + left;
}
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... |