이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
string ga, gb;
map<char, vi> prefixCharA;
map<char, vi> prefixCharB;
char characters[3] = {'A', 'T', 'C'};
void init(string a, string b)
{
int n = a.size();
ga = ' ' + a;
gb = ' ' + b;
for (char c : characters)
{
prefixCharA[c] = prefixCharB[c] = vi(n + 1, 0);
for (int i = 1; i <= n; i++)
{
prefixCharA[c][i] = (ga[i] == c) + prefixCharA[c][i - 1];
prefixCharB[c][i] = (gb[i] == c) + prefixCharB[c][i - 1];
}
}
}
int swapDistance(string &a, string b)
{
if (a == b)
return 0;
int res = 1e9 + 1;
for (int i = 0; i < b.size(); i++)
for (int j = i + 1; j < b.size(); j++)
{
if (b[i] == b[j] || a[i] == b[i] || a[j] == b[j])
continue;
swap(b[i], b[j]);
res = min(res, swapDistance(a, b) + 1);
swap(b[i], b[j]);
}
return res;
}
int get_distance(int x, int y)
{
x++, y++;
bool pos = true;
for (char c : characters)
{
int countInA = prefixCharA[c][y] - prefixCharA[c][x - 1];
int countInB = prefixCharB[c][y] - prefixCharB[c][x - 1];
pos &= (countInA == countInB);
}
if (!pos)
return -1;
string s1 = string(ga.begin() + x, ga.begin() + y + 1);
string s2 = string(gb.begin() + x, gb.begin() + y + 1);
return swapDistance(s1, s2);
}
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'int swapDistance(std::string&, std::string)':
dna.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i < b.size(); i++)
| ~~^~~~~~~~~~
dna.cpp:34:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int j = i + 1; j < b.size(); j++)
| ~~^~~~~~~~~~
# | 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... |