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>
#include <dna.h>
using ll = long long;
//#define int ll
using namespace std;
#define sz(x) (int)(x).size()
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, l, r) for(int i = l; i >= r; i--)
#define fi first
#define se second
#define mod 998244353
#define db(x) cerr << __LINE__ << " " << #x << " " << x << "\n"
using vi = vector<int>;
using pi = pair<int, int>;
const int N = 100005;
const ll inf = 3e18;
int f[N][3][3];
void init(std::string a, std::string b){
auto type = [&](char c){
if(c == 'A') return 0;
if(c == 'C') return 1;
if(c == 'T') return 2;
};
foru(i, 0, sz(a) - 1){
f[i + 1][type(a[i])][type(b[i])]++;
foru(j, 0, 2)
foru(k, 0, 2) f[i + 1][j][k] += f[i][j][k];
}
}
int get_distance(int x, int y){
int adj[3][3] = {};
int o[3] = {}, z[3] = {};
foru(i, 0, 2)
foru(j, 0, 2){
adj[i][j] = f[y + 1][i][j] - f[x][i][j];
o[i] += adj[i][j];
z[j] += adj[i][j];
}
foru(i, 0, 2)
if(o[i] != z[i]) return -1;
int res = 0;
foru(i, 0, 2)
foru(j, 0, i - 1){
adj[i][j] -= min(adj[i][j], adj[j][i]);
adj[j][i] -= min(adj[i][j], adj[j][i]);
res += min(adj[i][j], adj[j][i]);
}
int mx1 = max(adj[0][1], adj[1][0]);
int mx2 = max(adj[0][2], adj[2][0]);
int mx3 = max(adj[1][2], adj[2][1]);
assert(mx1 == mx2 and mx2 == mx3);
res += (mx1 << 1);
return res;
}
/*void solve(){
int n, q; cin >> n >> q;
string a, b; cin >> a >> b;
init(a, b);
while(q--){
int x, y; cin >> x >> y;
cout << get_distance(x, y) << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1; // cin >> t;
while(t--){
solve();
}
}*/
Compilation message (stderr)
dna.cpp: In lambda function:
dna.cpp:28:2: warning: control reaches end of non-void function [-Wreturn-type]
28 | };
| ^
# | 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... |