# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
838305 | SAAD | Mutating DNA (IOI21_dna) | C++17 | 35 ms | 9744 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 <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
#include "dna.h"
int nm[(int)1e6][3][3] ;
int cma[(int)1e6][3];
int cmb[(int)1e6][3];
void turn ( string&a ){
int k[120] ;
k['C'] = 1 , k['T'] = 2 ;
for(auto&i:a) i = k[i];
}
void init(string a, string b) {
int n = a.length();
turn(a);turn(b);
for (int i = 0; i < n; ++i)
{
nm[i][a[i]][b[i]]++;
cma[i][a[i]]++;
cmb[i][b[i]]++;
if ( i ) {
for ( int j = 0 ; j < 3 ; j++ ) {
cma[i][j] += cma[i-1][j] ;
cmb[i][j] += cmb[i-1][j] ;
for ( int k = 0 ; k < 3 ; k++ ) {
nm[i][j][k] += nm[i-1][j][k] ;
}
}
}
}
}
int get_distance(int x, int y) {
int baqee = 0 , ans = 0 ;
bool th = true ;
for ( int i = 0 ; i < 3 ; i++ ) {
int aa = cma[y][i] - (x?cma[x-1][i]:0) ;
int bb = cmb[y][i] - (x?cmb[x-1][i]:0) ;
if ( aa != bb ) th = false ;
}
if(!th) return -1 ;
for ( int i = 0 ; i < 3 ; i++ ) {
for ( int j = i+1 ; j < 3 ; j++ ) {
int a = nm[y][i][j] - (x?nm[x-1][i][j]:0) ;
swap(i,j);
int b = nm[y][i][j] - (x?nm[x-1][i][j]:0) ;
swap(i,j);
int mn = min(a,b);
ans += mn ;
a -= mn ; b -= mn ;
baqee = baqee + a + b ;
}
}
return ((baqee/3)*2) + ans ;
}
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... |