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;
string a, b;
vector<int> prefix;
vector<pair<int, int>> prefA;
vector<pair<int, int>> prefB;
void init(string A, string B) {
a = A;
b = B;
prefix.resize(A.length()+1, 0);
prefA.resize(A.length() +1, pair<int, int> {0, 0});
prefB.resize(A.length() +1, pair<int, int> {0, 0});
for(int i = 0;i<A.length();i++) {
prefA[i+1] = prefA[i];
prefB[i+1] = prefB[i];
if(A[i] != B[i]) {
prefix[i+1] = prefix[i] + 1;
}
else {
prefix[i+1] = prefix[i];
}
if(A[i] == A[0]) {
prefA[i+1].first = prefA[i].first + 1;
}
else {
prefA[i+1].second = prefA[i].second + 1;
}
if(B[i] == A[0]) {
prefB[i+1].first = prefB[i].first + 1;
}
else {
prefB[i+1].second = prefB[i].second + 1;
}
}
//for(int i:prefix)cout<<i<<'
//cout<<endl;
//for(pair<int, int> i:prefA)cout<<i.first<<' '<<i.second<<"}, {";
//cout<<endl;
//for(pair<int, int> i:prefB)cout<<i.first<<' '<<i.second<<"}, {";
//cout<<endl;
}
int get_distance(int x, int y) {
if(prefA[y+1].first - prefA[x].first != prefB[y+1].first - prefB[x].first or prefA[y+1].second - prefA[x].second != prefB[y+1].second - prefB[x].second) {
return -1;
}
return (prefix[y+1] - prefix[x])/2;
}
Compilation message (stderr)
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:14:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i = 0;i<A.length();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... |