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 long long ll;
#define ld long double
#define vf v[i].first
#define vs v[i].second
const ll MOD = 1e9 + 7;
void print(vector<int> &v) {
for (auto c:v)
cout << c << " ";
cout << "\n";
}
vector<int>pref = {0};
vector<int>prefA1 = {0};
vector<int>prefT1 = {0};
vector<int>prefA2 = {0};
vector<int>prefT2 = {0};
int n;
string c,d;
void init(string a, string b) {
n = a.size();
c = a;
d = b;
int a1=0,a2=0,b1=0,b2=0,ans=0;
for (int i = 0; i < n; ++i) {
if (a[i]!=b[i])
++ans;
pref.push_back(ans);
if (a[i]=='A')
a1++;
prefA1.push_back(a1);
if (a[i]=='T')
b1++;
prefT1.push_back(b1);
if (b[i]=='A')
a2++;
prefA2.push_back(a2);
if (b[i]=='T')
b2++;
prefT2.push_back(b2);
}
}
int get_distance(int x, int y) {
int ans = 0;
if (prefA1[y+1]-prefA1[x]!=prefA2[y+1]-prefA2[x] || prefT1[y+1]-prefT1[x]!=prefT2[y+1]-prefT2[x])
return -1;
return (pref[y+1]-pref[x]+1)/2;
}
/*int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string a,b;
cin >> a >> b;
init(a,b);
cout << get_distance(0,0);
cout << "\n";
print(pref);
print(prefA1);
print(prefA2);
print(prefT1);
print(prefT2);
}*/
Compilation message (stderr)
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:49:6: warning: unused variable 'ans' [-Wunused-variable]
49 | int ans = 0;
| ^~~
# | 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... |