# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
437403 | SAAD | Mutating DNA (IOI21_dna) | C++17 | 56 ms | 8060 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 <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
//#include "wall.h"
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
string dna = "ATC";
int aa[3][100002], bb[3][100002] , seg[100002][3][3] , ans[3][3] ;
int toidx( char x ) {
if (x == 'A') return 0;
if (x == 'T') return 1;
return 2;
}
void init(string a, string b) {
for (int i = 0; i < a.length(); i++) {
seg[i][toidx(a[i])][toidx(b[i])]++;
if (i) {
for (auto j : dna) {
for (auto u : dna) {
seg[i][toidx(j)][toidx(u)] += seg[i - 1][toidx(j)][toidx(u)];
}
}
}
aa[toidx(a[i])][i]++;
bb[toidx(b[i])][i]++;
if (i) {
for (auto j:dna) {
aa[toidx(j)][i] += aa[toidx(j)][i - 1];
bb[toidx(j)][i] += bb[toidx(j)][i - 1];
}
}
}
}
int get_distance(int x, int y) {
for (auto j : dna) {
int A = aa[toidx(j)][y] - (x>0?aa[toidx(j)][x-1]:0);
int B = bb[toidx(j)][y] - (x>0?bb[toidx(j)][x-1]:0);
if (A != B) return -1;
}
for (auto i : dna) {
for (auto j : dna) {
ans[toidx(i)][toidx(j)] = seg[y][toidx(i)][toidx(j)] - (x > 0 ? seg[x - 1][toidx(i)][toidx(j)]:0);
}
}
int res = 0 , res1 = 0 ;
for (int i = 0; i < 3; i++) {
for (int j = i+1; j < 3; j++) {
res += max(ans[i][j],ans[j][i]) - min(ans[i][j], ans[j][i]);
res1 = min(ans[i][j], ans[j][i]);
}
}
return ((res / 3) * 2) + res1;
}
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... |