# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
946744 | PenguinsAreCute | 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 "dna_ioi.h"
#include <bits/stdc++.h>
using namespace std;
#define MAXN 121010
struct pref_sum {
vector<int> v; int n;
pref_sum(): n(MAXN) {v.resize(n+1,0);}
void up(int x, int u) {v[x+1]=u;}
void compile() {for(int i=0;++i<=n;) v[i]+=v[i-1];}
int qry(int l, int r) {return v[r+1]-v[l];}
} pre[3][3];
void init(std::string a, std::string b) {
int n = a.size();
for(int i=-1;++i<n;) pre[a[i]%3][b[i]%3].up(i,1);
for(int i=-1;++i<3;) for(int j=0;j<3;j++) pre[i][j].compile();
}
int get_distance(int x, int y) {
int arr[3][3];
for(int i=-1;++i<3;) for(int j=-1;++j<3;) arr[i][j]=pre[i][j].qry(x,y);
for(int i=-1;++i<3;) {
int cnt = 0;
for(int j=-1;++j<3;) cnt+=arr[i][j]-arr[j][i];
if(cnt) return -1;
}
return max(arr[0][1],arr[1][0])+max(arr[0][2],arr[2][0])+min(arr[1][2],arr[2][1]);
}