# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445577 | hgmhc | 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>
#define REP(i,a,b) for (auto i = (a); i <= (b); ++i)
#define PER(i,a,b) for (auto i = (b); i >= (a); --i)
#define log2(x) (31-__builtin_clz(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SZ(x) (int)(x).size()
#define PB push_back
#define FI first
#define SE second
#define mup(x,y) x = min(x,y)
#define Mup(x,y) x = max(x,y)
#define debug(x) cout << #x << " is " << x << el
#define el '\n'
using namespace std; using ll = long long; using ii = pair<int,int>; using iii = tuple<int,int,int>;
void solution(); int main() {ios::sync_with_stdio(0); cin.tie(0); solution();}
const int N = 100003;
int n, q;
string s, t;
int solve(int l, int r) {
vector<int> a1, t1, c1;
vector<int> a2, t2, c2;
REP(i,l,r) {
if (s[i] == 'A') a1.push_back(i);
else if (s[i] == 'T') t1.push_back(i);
else c1.push_back(i);
if (t[i] == 'A') a2.push_back(i);
else if (t[i] == 'T') t2.push_back(i);
else c2.push_back(i);
}
int x = 0;
if (SZ(a1) != SZ(a2)) return -1;
if (SZ(t1) != SZ(t2)) return -1;
if (SZ(c1) != SZ(c2)) return -1;
REP(i,0,SZ(a1)-1) {
x += abs(a1[i]-a2[i]);
} REP(i,0,SZ(t1)-1) {
x += abs(t1[i]-t2[i]);
} REP(i,0,SZ(c1)-1) {
x += abs(c1[i]-c2[i]);
}
return x/2;
}
void input() {
cin >> n >> q;
cin >> s >> t;
}
void solution() {
input();
while (q--) {
int l, r; cin >> l >> r;
cout << solve(l,r) << el;
}
}