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.h"
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
/*
2. asama icin notlar:
1 - sinav baslayinca her problemi oku
en kolay gozukeni cozmeye basla
2 - bir soruya takilma
wa aliyorsan ve sorunu bulamadiysan hemen diger probleme gec
3 - her problemle ugras
4 - cozebildigin subtasklari impl et ve puanini arttir
5 - eger tum problemlerle ugrastiysan ve yapacagin bir sey kalmadi ise
random observationlar dene veya brute force atip pattern bulmaya calis
*/
vector<array<array<int,3>,3>> pre;
vector<array<int,3>> cnt1,cnt2;
int f(char x){
if(x=='A') return 0;
if(x=='T') return 1;
return 2;
}
void init(string a,string b){
array<array<int,3>,3> cur;
array<int,3> cr1,cr2;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
cr1[i]=cr2[i]=cur[i][j]=0;
int n = sz(a);
pre.resize(n);
cnt1.resize(n);
cnt2.resize(n);
for(int i=0;i<n;i++){
array<int,2> val={f(a[i]),f(b[i])};
cur[val[0]][val[1]]++;
cr1[f(a[i])]++;
cr2[f(b[i])]++;
pre[i]=cur;
cnt1[i]=cr1;
cnt2[i]=cr2;
}
}
int get_distance(int x,int y){
array<array<int,3>,3> res=pre[y];
array<int,3> cnt_a=cnt1[y];
array<int,3> cnt_b=cnt2[y];
if(x>0){
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
res[i][j]-=pre[x-1][i][j];
for(int i=0;i<3;i++){
cnt_a[i]-=cnt1[x-1][i];
cnt_b[i]-=cnt2[x-1][i];
}
}
if(cnt_a!=cnt_b) return -1;
int cur=min(res[0][2],res[2][0]);
int ans=cur;
res[0][2]-=cur;
res[2][0]-=cur;
cur=min(res[0][1],res[1][0]);
ans+=cur;
res[0][1]-=cur;
res[1][0]-=cur;
cur=min(res[1][2],res[2][1]);
ans+=cur;
res[1][2]-=cur;
res[2][1]-=cur;
int c1=min({res[0][1],res[1][2],res[2][0]});
int c2=min({res[0][2],res[2][1],res[1][0]});
if(c1>0 && c2>0) return -1;
ans+=c1*2;
ans+=c2*2;
return ans;
}
# | 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... |