이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#include "dna.h"
#include <bits/stdc++.h>
using namespace std;
#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"
const int N = 2e5 + 9 , mod = 1e9 + 7;
ll a[N] , b[N] , dp[N] , c[N][4] , d[N][4] , us[N][4][4];
int ok(int x , int y){
int s = 0, j;
for(j = 1; j <= 3; j++)
s += ((d[y][j] - (x > 0 ? d[x - 1][j] : 0)) != (c[y][j] - (x > 0 ? c[x - 1][j] : 0)));
return (s == 0);
}
int get(int x , int y , int l , int r){
int s = us[y][l][r] - (x > 0 ? us[x - 1][l][r] : 0);
int f = us[y][r][l] - (x > 0 ? us[x - 1][r][l] : 0);
return min(s , f);
}
int get_distance(int x , int y){
if(ok(x , y)){
int s = get(x , y , 1 , 2) + get(x , y , 1 , 3) + get(x , y , 2 , 3);
return (((dp[y] - (x > 0 ? dp[x - 1] : 0)) - 2 * s) * 2) / 3 + s;
}else
return -1;
}
void init(string a, string b){
map<char,int>mp;
mp['A'] = 1;
mp['C'] = 2;
mp['T'] = 3;
for(int i = 0; i < a.size(); i++){
if(i)
for(int j = 1; j <= 3; j++){
dp[i] = dp[i - 1] , c[i][j] = c[i - 1][j] , d[i][j] = d[i - 1][j];
for(int x = 1; x <= 3 ; x++)
us[i][j][x] = us[i - 1][j][x];
}
us[i][mp[a[i]]][mp[b[i]]]++;
c[i][mp[a[i]]]++;
d[i][mp[b[i]]]++;
dp[i] += (a[i] != b[i]);
}
}
/*
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
init("ATACAT", "ACTATA");
cout<<get_distance(4, 3)<<"\n";
}*/
// Author : حسن
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0; i < a.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... |