Submission #526272

#TimeUsernameProblemLanguageResultExecution timeMemory
526272pokmui9909Mutating DNA (IOI21_dna)C++17
100 / 100
100 ms31784 KiB
#include <bits/stdc++.h>
#include "dna.h"
using namespace std;
using ll = long long;

string A, B;
ll C1[100005][5], C2[100005][5];
ll S[100005][5][5];
ll f(char v){
    if(v == 'A') return 1;
    if(v == 'T') return 2;
    if(v == 'C') return 3;
}
void init(std::string a, std::string b){
    A = a, B = b;
    A = ' ' + A, B = ' ' + B;
    for(int i = 1; i <= A.size(); i++){
        for(int j = 1; j <= 3; j++){
            C1[i][j] = C1[i - 1][j];
        }
        C1[i][f(A[i])]++;
    }
    for(int i = 1; i <= B.size(); i++){
        for(int j = 1; j <= 3; j++){
            C2[i][j] = C2[i - 1][j];
        }
        C2[i][f(B[i])]++;
    }
    for(int i = 1; i <= A.size(); i++){
        for(int j = 1; j <= 3; j++){
            for(int k = 1; k <= 3; k++){
                S[i][j][k] = S[i - 1][j][k];
            }
        }
        S[i][f(A[i])][f(B[i])]++;
    }
}
bool Check(ll L, ll R){
    for(int i = 1; i <= 3; i++){
        if(C1[R][i] - C1[L - 1][i] != C2[R][i] - C2[L - 1][i]){
            return 0;
        }
    }
    return 1;
}
int get_distance(int x, int y){
    x++, y++;
    if(!Check(x, y)) return -1;
    vector<vector<ll>> T(5, vector<ll>(5));
    for(int i = 1; i <= 3; i++){
        for(int j = 1; j <= 3; j++){
            T[i][j] = S[y][i][j] - S[x - 1][i][j];
        }
    }
    ll ans = 0, K = 0;
    K = min(T[1][2], T[2][1]); ans += K; T[1][2] -= K, T[2][1] -= K;
    K = min(T[2][3], T[3][2]); ans += K; T[2][3] -= K, T[3][2] -= K;
    K = min(T[3][1], T[1][3]); ans += K; T[3][1] -= K, T[1][3] -= K;
    ans += max(T[1][2], T[2][1]) * 2;
    return ans;
}

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i = 1; i <= A.size(); i++){
      |                    ~~^~~~~~~~~~~
dna.cpp:23:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = 1; i <= B.size(); i++){
      |                    ~~^~~~~~~~~~~
dna.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i = 1; i <= A.size(); i++){
      |                    ~~^~~~~~~~~~~
dna.cpp: In function 'll f(char)':
dna.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
   13 | }
      | ^
#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...