이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include <iostream>
int sum[100001][3][3];
int get(char c) {
if(c == 'C')
return 0;
if(c == 'A')
return 1;
return 2;
}
void init(std::string a, std::string b) {
for(int i = 0; i < (int)a.size(); i++) {
//std::cout << get(a[i]) << " " << get(b[i]) << std::endl;
for(int t1 = 0; t1 < 3; t1++) {
for(int t2 = 0; t2 < 3; t2++) {
sum[i + 1][t1][t2] = sum[i][t1][t2];
}
}
sum[i + 1][get(a[i])][get(b[i])]++;
}
}
/*
0 1 2
0 {} [] []
1 [] {} []
2 [] [] {}
a b b a
b a -> b a
a b c a b c
b c a -> a b c
*/
int get_distance(int x, int y) {
int curr[3][3];
for(int t1 = 0; t1 < 3; t1++) {
for(int t2 = 0; t2 < 3; t2++) {
curr[t1][t2] = sum[y + 1][t1][t2] - sum[x][t1][t2];
}
}
for(int t = 0; t < 3; t++)
curr[t][t] = 0;
/*std::cout << curr[0][0] << " " << curr[1][0] << " " << curr[2][0] << std::endl;
std::cout << curr[0][1] << " " << curr[1][1] << " " << curr[2][1] << std::endl;
std::cout << curr[0][2] << " " << curr[1][2] << " " << curr[2][2] << std::endl;*/
int r = 0;
for(int t1 = 0; t1 < 3; t1++) {
for(int t2 = 0; t2 < 3; t2++) {
if(t1 != t2) {
int m = std::min(curr[t1][t2], curr[t2][t1]);
r += m;
curr[t1][t2] -= m;
curr[t2][t1] -= m;
}
}
}
for(int t1 = 0; t1 < 3; t1++) {
for(int t2 = 0; t2 < 3; t2++) {
for(int t3 = 0; t3 < 3; t3++) {
if(t1 != t2 && t2 != t3 && t1 != t3) {
int m = std::min(curr[t1][t2], std::min(curr[t2][t3], curr[t3][t1]));
r += 2 * m;
curr[t1][t2] -= m;
curr[t2][t3] -= m;
curr[t3][t1] -= m;
}
}
}
}
for(int t1 = 0; t1 < 3; t1++) {
for(int t2 = 0; t2 < 3; t2++) {
if(curr[t1][t2] != 0)
return -1;
}
}
return r;
}
# | 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... |