이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define sz(x) (ll)x.size()
#define MID ((l+r)/2)
#define F first
#define S second
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
#define pb push_back
#define ins insert
#define inf 1e9
typedef vector <ll> vi;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
void printVct(vi &v){
for (ll i =0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
vi a1,c1,a2,c2,f;
vi ac,ca,at,ta,tc,ct;
ll getRange(vi &v, ll l, ll r){
if (l == 0) return v[r];
return v[r] - v[l-1];
}
void init(string a, string b){
ll n = sz(a);
a1.resize(n),a2.resize(n),c1.resize(n),c2.resize(n),f.resize(n);
ac.resize(n),ca.resize(n),ta.resize(n),at.resize(n),ct.resize(n),tc.resize(n);
a1[0] = (a[0]=='A');
a2[0] = (b[0]=='A');
c1[0] = (a[0] == 'C');
c2[0] = (b[0] == 'C');
f[0] = (a[0] == b[0]);
ac[0] = (a[0] == 'A' && b[0] == 'C');
ca[0] = (a[0] == 'C' && b[0] == 'A');
at[0] = (a[0] == 'A' && b[0] == 'T');
ta[0] = (a[0] == 'T' && b[0] == 'A');
ct[0] = (a[0] == 'C' && b[0] == 'T');
tc[0] = (a[0] == 'T' && b[0] == 'C');
for (ll i =1; i<n; i++){
a1[i] = (a[i]=='A') + a1[i-1];
a2[i] = (b[i]=='A') + a2[i-1];
c1[i] = (a[i] == 'C') + c1[i-1];
c2[i] = (b[i] == 'C') + c2[i-1];
f[i] = (a[i] == b[i]) + f[i-1];
ac[i] = (a[i] == 'A' && b[i] == 'C') + ac[i-1];
ca[i] = (a[i] == 'C' && b[i] == 'A') + ca[i-1];
at[i] = (a[i] == 'A' && b[i] == 'T') + at[i-1];
ta[i] = (a[i] == 'T' && b[i] == 'A') + ta[i-1];
ct[i] = (a[i] == 'C' && b[i] == 'T') + ct[i-1];
tc[i] = (a[i] == 'T' && b[i] == 'C') + tc[i-1];
}
// printVct(a1);
// printVct(a2);
// printVct(c1);
// printVct(c2);
// printVct(f);
}
int get_distance(int x, int y) {
if (getRange(a1,x,y) == getRange(a2,x,y) && getRange(c1,x,y) == getRange(c2,x,y)){
ll range = y-x+1;
ll dif = range - getRange(f, x,y);
ll good = min(getRange(ac,x,y), getRange(ca,x,y)) + min(getRange(at,x,y), getRange(ta,x,y)) + min(getRange(tc,x,y), getRange(ct,x,y));
ll bad = dif - good;
ll ans = good + bad/3*2;
// dbg3(good, bad, ans);
return ans;
}
return -1;
}
# | 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... |