이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "dna.h"
#include <random>
#include <chrono>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=3e18;
const ld PI=3.14159265358979323846;
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
ll fpow(ll a,ll b,ll m)
{
if(!b) return 1;
ll ans=fpow(a*a%m,b/2,m);
return (b%2?ans*a%m:ans);
}
ll inv(ll a,ll m) {return fpow(a,m-2,m);}
#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
//#define int ll
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end()),uni(c)
const int N=1e5+1;
int n,cnt[N][3][3],sum1[N][3],sum2[N][3];
int id[26];
void init(string a,string b)
{
n=a.size();
id['A'-'A']=0;
id['C'-'A']=1;
id['T'-'A']=2;
rep(i,n)
{
rep(j,3)
{
sum1[i+1][j]=sum1[i][j];
sum2[i+1][j]=sum2[i][j];
}
rep(j,3) rep(k,3) cnt[i+1][j][k]=cnt[i][j][k];
sum1[i+1][id[a[i]-'A']]++;
sum2[i+1][id[b[i]-'A']]++;
cnt[i+1][id[a[i]-'A']][id[b[i]-'A']]++;
}
}
int get_distance(int x,int y)
{
x++,y++;
bool can=1;
rep(i,3) if(sum1[y][i]-sum1[x-1][i]!=sum2[y][i]-sum2[x-1][i]) can=0;
if(!can) return -1;
int ret=0,tot=0;
rep(i,3)
{
int a=cnt[y][i][(i+1)%3]-cnt[x-1][i][(i+1)%3];
int b=cnt[y][(i+1)%3][i]-cnt[x-1][(i+1)%3][i];
int c=min(a,b);
ret+=c;
tot+=a+b-2*c;
}
return ret+tot/3*2;
}
/*
signed main()
{
string a,b;
cin>>a>>b;
init(a,b);
int q;
cin>>q;
while(q--)
{
ll x,y;
cin>>x>>y;
cout<<get_distance(x,y)<<"\n";
}
}
*/
# | 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... |