제출 #999155

#제출 시각아이디문제언어결과실행 시간메모리
999155KasymKMutating DNA (IOI21_dna)C++17
0 / 100
22 ms3164 KiB
#include <bits/stdc++.h>
using namespace std;
string s3, s4;

void init(string s, string s2){
    s3 = s, s4 = s2;
}

int get_distance(int x, int y){
    string a = "", b = "";
    for(int i = x; i <= y; ++i)
        a += s3[i], b += s4[i];
    int n = (int)a.size();
    int sm = 0, sm2 = 0, sm3 = 0;
    for(int i = 0; i < n; ++i){
        if(a[i] == 'A')
            sm++;
        if(b[i] == 'A')
            sm--;
        if(a[i] == 'C')
            sm2++;
        if(b[i] == 'C')
            sm2--;
        if(a[i] == 'T')
            sm3++;
        if(b[i] == 'T')
            sm3--;
    }
    if(sm or sm2 or sm3)
        return -1;
    // O(q*m^2)
    int answer = 0;
    for(int i = 0; i < n; ++i){
        char c = a[i], c2 = b[i];
        if(c == c2)
            continue;
        for(int j = i+1; j < n; ++j)
            if(a[j] == c2 and b[j] == c){
                answer++;
                swap(a[i], a[j]);
            }
    }
    for(int i = 0; i < n; ++i)
        if(a[i] != b[i])
            answer += 2;
    return answer;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...