이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
int idx[100003][3][3] , n , ch[200] , A[100002][2] , T[100002][2] ;
void init(string a , string b ) {
memset(idx,0,sizeof(idx));
memset(A, 0, sizeof(A));
memset(T, 0, sizeof(T));
n = a.length();
ch['T'] = 1;
ch['C'] = 2;
for (int i = 0; i < n; i++) {
if (a[i] == 'A')A[i][0]++;
if(a[i]=='T')T[i][0]++;
if (b[i] == 'A')A[i][1]++;
if (b[i] == 'T')T[i][1]++;
a[i] = ch[a[i]]; b[i] = ch[b[i]];
idx[i][a[i]][b[i]]++;
if (i) {
A[i][0] += A[i - 1][0]; A[i][1] += A[i - 1][1];
T[i][0] += T[i - 1][0]; T[i][1] += T[i - 1][1];
for (int j = 0; j < 3;j++) {
for (int o = 0; o < 3; o++) {
idx[i][j][o] += idx[i-1][j][o];
}
}
}
}
}
int get_distance(int x, int y) {
if (A[y][0] - (x ? A[x - 1][0] : 0) != A[y][1] - (x ? A[x - 1][1] : 0))return -1;
if (T[y][0] - (x ? T[x - 1][0] : 0) != T[y][1] - (x ? T[x - 1][1] : 0))return -1;
int anoth = y-x+1;
int res = 0 ;
for (int i = 0; i < 3; i++ ) {
for (int j = i; j < 3; j++ ) {
if (i == j) {
anoth -= idx[y][i][j] - (x ? idx[x-1][i][j] : 0);
continue;
}
int c1 = idx[y][i][j] - (x ? idx[x-1][i][j] : 0);
int c2 = idx[y][j][i] - (x ? idx[x-1][j][i] : 0);
res += min(c1,c2);
anoth -= min(c1,c2);
}
}
return res + ( (anoth/3) * 2 );
}
/*int main() {
init("ATACAT", "ACTATA");
cout << get_distance(1, 3);
}*/
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:39:17: warning: array subscript has type 'char' [-Wchar-subscripts]
39 | a[i] = ch[a[i]]; b[i] = ch[b[i]];
| ^
dna.cpp:39:34: warning: array subscript has type 'char' [-Wchar-subscripts]
39 | a[i] = ch[a[i]]; b[i] = ch[b[i]];
| ^
dna.cpp:40:14: warning: array subscript has type 'char' [-Wchar-subscripts]
40 | idx[i][a[i]][b[i]]++;
| ^
dna.cpp:40:20: warning: array subscript has type 'char' [-Wchar-subscripts]
40 | idx[i][a[i]][b[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... |