Submission #1231332

#TimeUsernameProblemLanguageResultExecution timeMemory
1231332yixuan19DNA 돌연변이 (IOI21_dna)C++20
0 / 100
20 ms3172 KiB
#include "dna.h"
#include <vector>
#include <iostream>
#include <unordered_map>
#define N 100001

using namespace std;
vector <int> s1;
vector <int> s2;

unordered_map <char,int> convert;
bool st2 = true;

void init(std::string a, std::string b) {
    convert['A'] = 0;
    convert['C'] = 1;
    convert['T'] = 2;
	for (int i = 0; i < a.size(); ++i){
        if (convert[a[i]] == 1 || convert[b[i]] == 1) st2 = false;
		s1.push_back(convert[a[i]]);
        s2.push_back(convert[b[i]]);
	}
}

int get_distance(int x, int y) {
    vector<int>section1;
    vector<int>section2;
    int numA = 0;
    int numT = 0;
    if (!st2){
        vector<int> occ1(3,0);
        vector<int> occ2(3,0);
        

        for (int i = x; i <= y; ++i){
            occ1[s1[i]]++;
            section1.push_back(s1[i]);
        }
        for (int i = x; i <= y; ++i){
            occ2[s2[i]]++;
            section2.push_back(s2[i]);
        }
        if (occ1 != occ2){
            return -1;
        }
        // for (int i: section1){
        //     cout<<i<<' ';
        // }cout<<endl;
    

        if (section1 == section2){
            return 0;
        }

        swap(section1[0], section1[1]);
        if (section1 == section2){
            return 1;
        }
        swap(section1[0], section1[1]);

        swap(section1[1], section1[2]);
        if (section1 == section2){
            return 1;
        }
        swap(section1[1], section1[2]);

        swap(section1[0], section1[2]);
        if (section1 == section2){
            return 1;
        }
        swap(section1[0], section1[2]);
        return 2;
    }else{
        for (int i = x; i <= y; ++i){
            if (s1[i] != s2[i]){
                section1.push_back(s1[i]);
                section2.push_back(s2[i]);
            }
        }
        if (section1.size()%2 != 0){
            return -1;
        }else{
            return section1.size()/2;
        }
    }
}
#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...