Submission #1103119

#TimeUsernameProblemLanguageResultExecution timeMemory
1103119agrim_09DNA 돌연변이 (IOI21_dna)C++17
0 / 100
28 ms9220 KiB

#include <bits/stdc++.h>
using namespace std; 
#define pb push_back

#ifndef LOCAL
    #include "dna.h"
#endif // LOCAL
 
int val(char a, char b){
    if(a==b){
        return -1;
    }
    if(a=='1'){
       return (b-'2');
    }
    if(a=='2'){
        if(b=='1'){
            return 2;
        }
        return 3;
    }
    if(a=='3'){
        if(b=='1'){
            return 4;
        }
        return 5;
    }
    return -1;
}
int n; vector<vector<int>>cnt; string s1, s2;

void init(string p, string q){
    s1 = p, s2 = q;
    n = s1.size(); vector<int>temp(6,0);
    for(int i = 0;i<n;i++){
        cnt.pb(temp);
    }

    int tmp = val(s1[0],s2[0]);
    if(tmp!=-1){
        cnt[0][val(s1[0],s2[0])] = 1;
    }
 
    for(int i = 1;i<n;i++){
        for(int j = 0;j<6;j++){
            cnt[i][j] = cnt[i-1][j];
        }
        int tmp = val(s1[i],s2[i]);
        if(tmp!=-1){
            cnt[i][val(s1[i],s2[i])]++;
        }
    }
}

int get_distance(int l, int r){
    int x1 = cnt[r][0], x2 = cnt[r][1], y1 = cnt[r][2], y2 = cnt[r][3];
    int z1 = cnt[r][4], z2 = cnt[r][5];

    if(l>0){
        x1 -= cnt[l-1][0], x2 -= cnt[l-1][1], y1 -= cnt[l-1][2], y2 -= cnt[l-1][3];
        z1 -= cnt[l-1][4], z2 -= cnt[l-1][5]; 
    }

    int ans = min(x1,y1) + min(x2,z1) + min(y2,z2);
    set<int>front; set<int>end;

    int r1 = abs(x1-y1), r2 =abs(x2-z1), r3 = abs(y2-z2);

    if(x1>y1){
        front.insert(1); end.insert(2); 
    }
    if(y1>x1){
        front.insert(2); end.insert(1);
    }
    if(x2>z1){
        front.insert(1); end.insert(3);
    }
    if(z1>x2){
        front.insert(3); end.insert(1); 
    }
    if(y2>z2){
        front.insert(2); end.insert(3); 
    }
    if(z2>y2){
        front.insert(3); end.insert(2); 
    }

    bool yes = (front==end and r1==r2 and r2==r3);
    if(yes){
        return ans + 2*r1;
    }
    else{
        return -1;
    }
}
#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...