#include<bits/stdc++.h>
using namespace std;
#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ll long long
#define _ << " " <<
template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}
const int N=1e5+5;
string T="ATC";
int n,p[N][3][3],c[3][3],tmp[3];
string a,b;
void init(string _a, string _b){
a=_a, b=_b;
n=a.size();
a=" "+a, b=" "+b;
foru(i,1,n){
rep(j,3) rep(k,3){
p[i][j][k]=p[i-1][j][k]+(a[i]==T[j]&&b[i]==T[k]);
}
}
}
int get_distance(int x, int y){
++x; ++y;
rep(j,3) rep(k,3){
c[j][k]=p[y][j][k]-p[x-1][j][k];
}
int res=0;
rep(j,3) rep(k,3) if(j!=k){
int t=min(c[j][k],c[k][j]);
c[j][k]-=t; c[k][j]-=t; res+=t;
}
rep(j,3) rep(k,3) if(j!=k){ /// j->k
rep(i,3) if(i!=j){ /// i->j
int t=min(c[j][k],c[i][j]);
c[j][k]-=t; c[i][j]-=t;
c[j][j]+=t; c[i][k]+=t;
res+=t;
}
}
rep(j,3) rep(k,3) if(j!=k && c[j][k]>0) return -1;
return res;
}
| # | 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... |