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>
#ifdef GUDEB
#define D(x) cerr << #x << ": " << (x) << '\n';
#define ifdeb if(true)
#else
#define D(x) ;
#define ifdeb if(false)
#endif
#define all(x) begin(x), end(x)
using namespace std;
using ull = unsigned long long;
using ll = long long;
// #define int ll;
int dedna(char c) {
switch(c) {
break;case 'A':
return 0;
break;case 'C':
return 1;
break;case 'T':
return 2;
break;default:
return -1;
}
}
int n;
vector<int> psa[3];
vector<int> psb[3];
vector<int> pss[3][3];
void init(std::string a, std::string b) {
n = a.size();
for(auto& ps : psa) {
ps.resize(n+1);
ps[0] = 0;
}
for(auto& ps : psb) {
ps.resize(n+1);
ps[0] = 0;
}
for(auto& ps : pss) {
for(auto& p : ps) {
p.resize(n+1);
p[0] = 0;
}
}
for(int j = 0; j < 3; ++j) {
for(int i = 0; i < n; ++i) {
psa[j][i+1] = psa[j][i] + (dedna(a[i]) == j);
}
}
for(int j = 0; j < 3; ++j) {
for(int i = 0; i < n; ++i) {
psb[j][i+1] = psb[j][i] + (dedna(b[i]) == j);
}
}
for(int j = 0; j < 3; ++j) {
for(int k = 0; k < 3; ++k) {
for(int i = 0; i < n; ++i) {
pss[j][k][i+1] = pss[j][k][i] + (dedna(a[i]) == j && dedna(b[i]) == k);
}
}
}
}
int get_distance(int x, int y) {
int ca[3];
for(int i = 0; i < 3; ++i)
ca[i] = psa[i][y+1] - psa[i][x];
int cb[3];
for(int i = 0; i < 3; ++i)
cb[i] = psb[i][y+1] - psb[i][x];
for(int i = 0; i < 3; ++i)
if(ca[i] != cb[i]) return -1;
int cs[3][3];
for(int i = 0; i < 3; ++i)
for(int j = 0; j < 3; ++j) {
cs[i][j] = pss[i][j][y+1] - pss[i][j][x];
}
int lf[3];
int d = 0;
for(int i = 0; i < 3; ++i) {
int o = (i+1)%3;
int m = min(cs[i][o], cs[o][i]);
d += m;
lf[i] = max(cs[i][o], cs[o][i]) - m;
}
d += 2*lf[0];
return d;
}
# | 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... |