이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define pf push_front
#define pi pair<int,int>
string a,b;
const int MAX = 1e5+1;
int n;
ll how[2][MAX][3];
ll cnt[MAX][3];
map<char,int>mtch;
void init(string A, string B){
a = A;
b = B;
mtch['A']=0;
mtch['C']=1;
mtch['T']=2;
for(int i = 0; i <a.size(); i++){
for(int j = 0; j<3; j++){
how[0][i+1][j] = how[0][i][j] ;
how[1][i+1][j] = how[1][i][j] ;
// cnt[i+1][j] = cnt[i][j];
}
// cout << mtch[A[i]]<<" s "<< mtch[B[i]]<<endl;
how[0][i+1][mtch[A[i]]]++;
how[1][i+1][mtch[B[i]]]++;
/* if(A[i]!=B[i])[
cnt[i+2][mtch[B[i]]]++;
}*/
}
}
int get_distance(int x, int y){
ll add = 0;
ll sub = 0;
ll mp[3];
memset(mp,0,sizeof(mp));
int vala,valb;
for(int i =0; i < 3; i++){
vala = how[0][y+1][i]-how[0][x][i];
valb = how[1][y+1][i]-how[1][x][i];
// cout<< vala<<" " << valb << endl;
if(vala!=valb) return -1;
}
for(int i = x; i<= y; i++){
if(a[i]!=b[i]){
if(mp[mtch[a[i]]]){
//sub++;
mp[mtch[a[i]]]--;
}
else{
mp[mtch[b[i]]]++;
add++;
}
}
}
//cout << add<<" "<<sub<< " "<< endl;
return add;
}
/*
int main(){
int n,q ;
cin >> n >> q;
string a,b;
cin >> a >>b;
init(a,b);
int x,y;
while(q--){
cin >> x >>y;
cout << get_distance(x,y)<<endl;
}
}
*/
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i = 0; i <a.size(); i++){
| ~~^~~~~~~~~
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:44:8: warning: unused variable 'sub' [-Wunused-variable]
44 | ll sub = 0;
| ^~~
# | 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... |