이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "dna.h"
using namespace std;
string a, b;
struct SegTree{
vector<int>sTree;
void Build(int node, int l, int r){
if(l == r){
sTree[node] = (a[l] != b[l]);
}
else{
int mid = (l + r) >> 1;
Build(node * 2, l, mid);
Build(node * 2 + 1, mid + 1, r);
sTree[node] = sTree[node * 2] + sTree[node * 2 + 1];
}
}
int Query(int node, int l, int r, int ql, int qr){
if(ql <= l && r <= qr)return sTree[node];
if(ql > r || qr < l)return 0;
int mid = (l + r) >> 1;
int Lc = Query(node * 2, l, mid, ql, qr);
int Rc = Query(node * 2 + 1, mid + 1, r, ql, qr);
return Lc + Rc;
}
};
SegTree st;
struct ATC{
int A = 0, T = 0, C = 0;
};
vector<ATC>cnt_A, cnt_B;
void init(string A, string B){
a = " ", b = " ";
a += A, b += B;
cnt_A.resize(a.length());
cnt_B.resize(a.length());
st.sTree.resize(4 * A.length());
st.Build(1, 1, A.length());
for(int i = 1;i <= A.length();++i){
cnt_A[i].A = cnt_A[i - 1].A;
cnt_A[i].T = cnt_A[i - 1].T;
cnt_A[i].C = cnt_A[i - 1].C;
if(a[i] == 'A')cnt_A[i].A++;
if(a[i] == 'T')cnt_A[i].T++;
if(a[i] == 'C')cnt_A[i].C++;
}
for(int i = 1;i <= A.length();++i){
cnt_B[i].A = cnt_B[i - 1].A;
cnt_B[i].T = cnt_B[i - 1].T;
cnt_B[i].C = cnt_B[i - 1].C;
if(b[i] == 'A')cnt_B[i].A++;
if(b[i] == 'T')cnt_B[i].T++;
if(b[i] == 'C')cnt_B[i].C++;
}
}
int get_distance(int x, int y){
x++;
y++;
int q = st.Query(1, 1, a.length() - 1, x, y);
ATC num1, num2;
num1.A = cnt_A[y].A - cnt_A[x - 1].A;
num1.T = cnt_A[y].T - cnt_A[x - 1].T;
num1.C = cnt_A[y].C - cnt_A[x - 1].C;
num2.A = cnt_B[y].A - cnt_B[x - 1].A;
num2.T = cnt_B[y].T - cnt_B[x - 1].T;
num2.C = cnt_B[y].C - cnt_B[x - 1].C;
// cout << num1.A << " " << num1.T << " " << num1.C << '\n';
// cout << num2.A << " " << num2.T << " " << num2.C;
if(num1.A != num2.A)return -1;
if(num1.T != num2.T)return -1;
if(num1.C != num2.C)return -1;
if(!q)return 0;
return q - 1;
}
//int main(){
// init("TAA", "TAA");
// cout << get_distance(2, 2);
//}
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i = 1;i <= A.length();++i){
| ~~^~~~~~~~~~~~~
dna.cpp:47:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 1;i <= A.length();++i){
| ~~^~~~~~~~~~~~~
# | 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... |