이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string a1,b1,s="ACT";
int n,cnt[3][2][100005],p[3][3][100005];
int get_cnt(int ind1,int ind2,int l,int r) {
if(!l) return cnt[ind1][ind2][r];
return cnt[ind1][ind2][r]-cnt[ind1][ind2][l-1];
}
int get_p(int ind1,int ind2,int l,int r) {
if(!l) return p[ind1][ind2][r];
return p[ind1][ind2][r]-p[ind1][ind2][l-1];
}
void init(std::string a, std::string b) {
n=a.size();
for(int i=0;i<n;i++) {
for(int j=0;j<3;j++) {
if(a[i]==s[j]) cnt[j][0][i]=1;
if(b[i]==s[j]) cnt[j][1][i]=1;
}
for(int j=0;j<3;j++) {
for(int k=0;k<2;k++) {
if(i) cnt[j][k][i]+=cnt[j][k][i-1];
}
}
if(a[i]==b[i]) continue;
for(int j=0;j<3;j++) {
for(int k=0;k<3;k++) {
if(a[i]==s[j] && b[i]==s[k]) p[j][k][i]=1;
}
}
for(int j=0;j<3;j++) {
for(int k=0;k<3;k++) {
if(i) p[j][k][i]+=p[j][k][i-1];
}
}
}
/*for(int i=0;i<3;i++) {
for(int j=0;j<n;j++) {
cout << cnt[i][0][j] << " ";
}
cout << "\n";
}*/
}
int get_distance(int x, int y) {
int diffa=get_cnt(0,0,x,y)-get_cnt(0,1,x,y);
int diffc=get_cnt(1,0,x,y)-get_cnt(1,1,x,y);
int difft=get_cnt(2,0,x,y)-get_cnt(2,1,x,y);
//cout << x << " " << y << " " << diffa << " " << diffc << " " << difft << "\n";
if(diffa!=0 || diffc!=0 || difft!=0) return -1;
int l=y-x+1,ret=0;
for(int i=0;i<3;i++) {
for(int j=i+1;j<3;j++) {
int sum=min(get_p(i,j,x,y),get_p(j,i,x,y));
ret+=sum;
l-=sum*2;
}
}
return ret+(l/3)*2;
}
# | 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... |