# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
510018 | YaserFaisal | Mutating DNA (IOI21_dna) | C++17 | 0 ms | 0 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>
#include "dna.h"
using namespace std ;
int ps[100009][20] ;
void init ( string a , string b )
{
int n = a.size() ;
for ( int i = 0 ; i < n ; i++ )
{
if ( a[i] == 'A' && b[i] == 'C' ) ps[i+1][1]++ ;
if ( a[i] == 'C' && b[i] == 'A' ) ps[i+1][2]++ ;
if ( a[i] == 'C' && b[i] == 'T' ) ps[i+1][3]++ ;
if ( a[i] == 'T' && b[i] == 'C' ) ps[i+1][4]++ ;
if ( a[i] == 'T' && b[i] == 'A' ) ps[i+1][5]++ ;
if ( a[i] == 'A' && b[i] == 'T' ) ps[i+1][6]++ ;
if ( a[i] == 'A' ) ps[i+1][7]++ ;
if ( a[i] == 'C' ) ps[i+1][8]++ ;
if ( a[i] == 'T' ) ps[i+1][9]++ ;
if ( b[i] == 'A' ) ps[i+1][10]++ ;
if ( b[i] == 'C' ) ps[i+1][11]++ ;
if ( b[i] == 'T' ) ps[i+1][12]++ ;
for ( int j = 1 ; j <= 12 ; j++ ) ps[i+1][j]+=ps[i][j] ;
}
}
// ACT
// 1 AC
// 2 CA
// 3 CT
// 4 TC
// 5 TA
// 6 AT
int get_distance ( int x , int y )
{
y++ ;
for ( int i = 7 ; i <= 9 ; i++ )
{
if ( (ps[y][i]-ps[x][i]) != (ps[y][i+3]-ps[x][i+3]) ) return -1 ;
}
int ans = 0 , n = y-x ;
int a = ps[y][1] - ps[x][1] ;
int b = ps[y][2] - ps[x][2] ;
int c = ps[y][3] - ps[x][3] ;
int d = ps[y][4] - ps[x][4] ;
int e = ps[y][5] - ps[x][5] ;
int f = ps[y][6] - ps[x][6] ;
//cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl ;
int g = min(a,b) + min(c,d) + min(e,f) ;
ans = g + ((n-g)/3)*2 ;
return ans ;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string a , b ; cin >> a >> b ;
init(a,b) ;
int q ; cin >> q ;
while(q--)
{
int x , y ; cin >> x >> y ;
cout << get_distance(x,y) ;
}
}