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;
typedef long long ll;
int n, S[100100][9], mp[202];
void init(std::string a, std::string b) {
n = a.size();
mp['A'] = 0, mp['C'] = 1, mp['T'] = 2;
for (int i=0;i<n;i++){
int cur = mp[a[i]]*3+mp[b[i]];
for (int j=0;j<9;j++) S[i+1][j] = S[i][j];
S[i+1][cur]++;
}
}
int get_distance(int x, int y) {
x++, y++;
int cur[9], ret = 0;
for (int j=0;j<9;j++) cur[j] = S[y][j] - S[x-1][j];
//for (int j=0;j<9;j++) printf("%d ", cur[j]);
//printf("\n");
if (cur[0]+cur[1]+cur[2]!=cur[0]+cur[3]+cur[6]) return -1;
if (cur[3]+cur[4]+cur[5]!=cur[1]+cur[4]+cur[7]) return -1;
if (cur[6]+cur[7]+cur[8]!=cur[2]+cur[5]+cur[8]) return -1;
int tmp1 = min(cur[2], cur[6]), tmp2 = min(cur[1], cur[3]), tmp3 = min(cur[5], cur[7]);
ret += tmp1+tmp2+tmp3;
cur[2] -= tmp1, cur[6] -= tmp1;
cur[1] -= tmp2, cur[3] -= tmp2;
cur[5] -= tmp3, cur[7] -= tmp3;
return ret+cur[1]*2+cur[2]*2;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:12:26: warning: array subscript has type 'char' [-Wchar-subscripts]
12 | int cur = mp[a[i]]*3+mp[b[i]];
| ^
dna.cpp:12:37: warning: array subscript has type 'char' [-Wchar-subscripts]
12 | int cur = mp[a[i]]*3+mp[b[i]];
| ^
# | 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... |