이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "dna.h"
#include<bits/stdc++.h>
using namespace std;
int a[100004][2][2];
void init(string A, string B) {
int n = A.size();
for (int i = 0; i < n; i ++) {
if ( A[i] == 'T') A[i] = 'B';
if ( B[i] == 'T') B[i] = 'B';
A[i] += 32;
B[i] += 32;
for (int j = 0; j <= 2; j ++) {
for (int r = 0; r <= 2; r ++) {
if ( i == 0) a[i][j][r] = 0;
else a[i][j][r] = a[i - 1][j][r];
}
}
int x = A[i] - 'a';
int y = B[i] - 'a';
a[i][x][y] ++;
}
}
int cnt(int l, int r, int x, int y){
int s= a[r][x][y];
if ( l == 0) return s;
s -= (a[l - 1][x][y]);
return s;
}
int get_distance(int x, int y) {
int ab = cnt(x, y, 0, 1), ba = cnt(x, y, 1, 0), ac = cnt(x, y, 0, 2), ca = cnt(x, y, 2, 0), bc = cnt(x, y, 1, 2), cb = cnt(x, y, 2, 1);
x = min(ab, ba);
ab -= x;
ba -= x;
x = min(ac, ca);
ac -= x;
ca -= x;
x = min(bc, cb);
bc -= x;
cb -= x;
ab += ba;
ac += ca;
bc += cb;
int s = ab + bc + ac;
if ( ab * 2 == s) return ab;
if ( ac * 2 == s) return ac;
if ( bc * 2 == s) return bc;
return -1;
}
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'int get_distance(int, int)':
dna.cpp:25:15: warning: array subscript 2 is above array bounds of 'int [2][2]' [-Warray-bounds]
25 | int s= a[r][x][y];
| ~~~~~~^
dna.cpp:27:18: warning: array subscript 2 is above array bounds of 'int [2][2]' [-Warray-bounds]
27 | s -= (a[l - 1][x][y]);
| ~~~~~~~~~~^
dna.cpp:25:15: warning: array subscript 2 is above array bounds of 'int [2][2]' [-Warray-bounds]
25 | int s= a[r][x][y];
| ~~~~~~^
dna.cpp:27:18: warning: array subscript 2 is above array bounds of 'int [2][2]' [-Warray-bounds]
27 | s -= (a[l - 1][x][y]);
| ~~~~~~~~~~^
# | 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... |