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>
using namespace std;
typedef vector<int> VI;
const int maxN = 100'000;
vector<VI> A(maxN+4, VI(3)), B(maxN+4, VI(3)), AW(maxN+4, VI(2)), TW(maxN+4, VI(2)), CW(maxN+4, VI(2));
void init(string a, string b) {
for (int i = 1; i<=a.size(); ++i) {
A[i] = A[i-1], B[i] = B[i-1], AW[i] = AW[i-1], TW[i] = TW[i-1], CW[i] = CW[i-1];
if (a[i-1]=='A') {
++A[i][0];
if (b[i-1]=='T') ++TW[i][0];
else if (b[i-1]=='C') ++CW[i][0];
}
else if (a[i-1]=='T') {
++A[i][1];
if (b[i-1]=='A') ++AW[i][0];
else if (b[i-1]=='C') ++CW[i][1];
}
else {
++A[i][2];
if (b[i-1]=='A') ++AW[i][1];
else if (b[i-1]=='T') +TW[i][1];
}
if (b[i-1]=='A') ++B[i][0];
else if (b[i-1]=='T') ++B[i][1];
else ++B[i][2];
}
}
int get_distance(int x, int y) {
if ( (A[y+1][0] - A[x][0] == B[y+1][0] - B[x][0]) && (A[y+1][1] - A[x][1] == B[y+1][1] - B[x][1]) && (A[y+1][2] - A[x][2] == B[y+1][2] - B[x][2]) ) {
if (AW[y+1][0] - AW[x][0] || AW[y+1][1]-AW[x][1] || TW[y+1][0]-TW[x][0] || TW[y+1][1]-TW[x][1] || CW[y+1][0] - CW[x][0] || CW[y+1][1] - CW[x][1])
return min(AW[y+1][0] - AW[x][0], TW[y+1][0]-TW[x][0]) + min(AW[y+1][1] - AW[x][1], CW[y+1][0]-CW[x][0]) + min(CW[y+1][1] - CW[x][1], TW[y+1][1]-TW[x][1])
+ (abs( (CW[y+1][1] - CW[x][1]) - (TW[y+1][1]-TW[x][1]) ) + abs( (CW[y+1][0] - CW[x][0]) - (AW[y+1][1]-AW[x][1]) ) +
abs( (AW[y+1][0] - AW[x][0]) - (TW[y+1][0]-TW[x][0]) ) )/3*2;
return 0;
}
return -1;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for (int i = 1; i<=a.size(); ++i) {
| ~^~~~~~~~~~
dna.cpp:23:35: warning: value computed is not used [-Wunused-value]
23 | else if (b[i-1]=='T') +TW[i][1];
# | 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... |