이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <algorithm>
#include <numeric>
#include <vector>
std::vector<int> psums[9];
const std::vector<std::string> poss = {"AT", "AC", "TC", "TA", "CA", "CT"};
const std::vector<std::string> poss_exh = {"AT", "AC", "TC", "TA", "CA",
"CT", "AA", "TT", "CC"};
const std::vector<std::pair<std::string, std::string>> complements = {
{"AT", "TA"}, {"AC", "CA"}, {"TC", "CT"}};
const std::vector<char> letters = {'A', 'T', 'C'};
int n;
std::vector<int> A_psum[3], B_psum[3];
std::vector<std::string> to_permute = {"ATTCCA", "ACCTTA", "TCCAAT",
"TAACCT", "CAATTC", "CTTAAC"};
int gi(char c) {
for (int i = 0; i < letters.size(); ++i) {
if (c == letters[i]) {
return i;
}
}
return -1;
}
int gi(std::string str) {
for (int i = 0; i < poss_exh.size(); ++i) {
if (str == poss_exh[i]) {
return i;
}
}
return -1;
}
void init(std::string a, std::string b) {
n = a.length();
for (auto &p : poss) {
psums[gi(p)].resize(n + 1);
}
for (auto &c : letters) {
A_psum[gi(c)].resize(n + 1);
B_psum[gi(c)].resize(n + 1);
psums[gi(std::string(2, c))].resize(n + 1);
}
a = " " + a;
b = " " + b;
for (int i = 1; i <= n; ++i) {
psums[gi(std::string(1, a[i]) + std::string(1, b[i]))][i]++;
A_psum[gi(a[i])][i]++;
B_psum[gi(b[i])][i]++;
}
for (auto &p : psums) {
std::vector<int> res(p.size());
std::partial_sum(p.begin(), p.end(), res.begin());
p = res;
}
for (auto &p : A_psum) {
std::vector<int> res(p.size());
std::partial_sum(p.begin(), p.end(), res.begin());
p = res;
}
for (auto &p : B_psum) {
std::vector<int> res(p.size());
std::partial_sum(p.begin(), p.end(), res.begin());
p = res;
}
}
int get_distance(int x, int y) {
++x, ++y;
for (auto &ch : letters) {
if (A_psum[gi(ch)][y] - A_psum[gi(ch)][x - 1] !=
B_psum[gi(ch)][y] - B_psum[gi(ch)][x - 1]) {
return -1;
}
}
std::vector<int> sums(9);
for (auto &p : poss) {
sums[gi(p)] = psums[gi(p)][y] - psums[gi(p)][x - 1];
}
int ans = 0;
for (auto &[u, v] : complements) {
int cur = std::min(sums[gi(u)], sums[gi(v)]);
ans += cur;
sums[gi(u)] -= cur, sums[gi(v)] -= cur;
}
int final_ans = 1e9;
std::vector<std::string> cur_to_perm;
for (auto &s : to_permute) {
auto a = gi(s.substr(0, 2));
auto b = gi(s.substr(2, 2));
auto c = gi(s.substr(4, 2));
int cur = std::min({sums[a], sums[b], sums[c]});
if (cur != 0) {
cur_to_perm.push_back(s);
}
}
do {
auto mp = sums;
auto cur_ans = ans;
for (auto &s : cur_to_perm) {
auto a = gi(s.substr(0, 2));
auto b = gi(s.substr(2, 2));
auto c = gi(s.substr(4, 2));
int cur = std::min({mp[a], mp[b], mp[c]});
cur_ans += 2 * cur;
mp[a] -= cur, mp[b] -= cur, mp[c] -= cur;
}
final_ans = std::min(final_ans, cur_ans);
} while (std::next_permutation(cur_to_perm.begin(), cur_to_perm.end()));
return final_ans == int(1e9) ? ans : final_ans;
}
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'int gi(char)':
dna.cpp:19:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < letters.size(); ++i) {
| ~~^~~~~~~~~~~~~~~~
dna.cpp: In function 'int gi(std::string)':
dna.cpp:28:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = 0; i < poss_exh.size(); ++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... |