이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include<bits/stdc++.h>
using namespace std;
string a, b;
vector<int> prefix;
vector<pair<int, int>> prefA;
vector<pair<int, int>> prefB;
void init(string A, string B) {
a = A;
b = B;
prefix.resize(A.length()+1, 0);
prefA.resize(A.length() +1, pair<int, int> {0, 0});
prefB.resize(A.length() +1, pair<int, int> {0, 0});
for(int i = 0;i<A.length();i++) {
prefA[i+1] = prefA[i];
prefB[i+1] = prefB[i];
if(A[i] != B[i]) {
prefix[i+1] = prefix[i] + 1;
}
else {
prefix[i+1] = prefix[i];
}
if(A[i] == A[0]) {
prefA[i+1].first = prefA[i].first + 1;
}
else {
prefA[i+1].second = prefA[i].second + 1;
}
if(B[i] == A[0]) {
prefB[i+1].first = prefB[i].first + 1;
}
else {
prefB[i+1].second = prefB[i].second + 1;
}
}
//for(int i:prefix)cout<<i<<'
//cout<<endl;
//for(pair<int, int> i:prefA)cout<<i.first<<' '<<i.second<<"}, {";
//cout<<endl;
//for(pair<int, int> i:prefB)cout<<i.first<<' '<<i.second<<"}, {";
//cout<<endl;
}
int get_distance(int x, int y) {
if(y - x<= 2) {
string A = "", B = "";
if(y - x == 0) {
if(a[x] == b[x])return 0;
return -1;
}
if(y-x == 1) {
if(a[x] == b[x] and a[y] == b[y])return 0;
if(a[y] == b[x] and a[x] == b[y])return 1;
return -1;
}
else {
int c = 0;
set<char> s;
for(int i = x;i<=y;i++) {
s.insert(a[i]);
A.push_back(a[i]);
B.push_back(b[i]);
if(a[i] != b[i])c++;
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
if(A != B) {
return -1;
}
if(s.size() == 1)return 0;
if(c == 0)return 0;
if(s.size() == 2 and c == 2)return 1;
if(s.size() == 3 and c == 2)return 1;
if(s.size() == 3 and c == 3)return 2;
return 0;
}
}
if(prefA[y+1].first - prefA[x].first != prefB[y+1].first - prefB[x].first or prefA[y+1].second - prefA[x].second != prefB[y+1].second - prefB[x].second) {
return -1;
}
return (prefix[y+1] - prefix[x])/2;
}
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:14:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i = 0;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... |