Submission #1363597

#TimeUsernameProblemLanguageResultExecution timeMemory
1363597yavor_ptvMutating DNA (IOI21_dna)C++20
35 / 100
19 ms5288 KiB
// SUBTASK 1 -> 3
#include <bits/stdc++.h>
#include "dna.h"
//#include "grader.cpp"

using namespace std;

string a, b;
vector <int> pref;
vector <vector<int>> pref_a;
vector <vector<int>> pref_b;

void init(string A, string B)
{
    a = A;
    b = B;
    int n = a.size();
    pref.resize(n);
    pref_a.resize(2, vector<int>(n));
    pref_b.resize(2, vector<int>(n));

    for (int i = 0; i < n; i++)
    {
        if (a[i] == 'A')
        {
            pref_a[0][i] = i > 0 ? pref_a[0][i - 1] + 1 : 1;
        }
        else pref_a[0][i] = i > 0 ? pref_a[0][i - 1] : 0;

        if (a[i] == 'T')
        {
            pref_a[1][i] = i > 0 ? pref_a[1][i - 1] + 1 : 1;
        }
        else pref_a[1][i] = i > 0 ? pref_a[1][i - 1] : 0;

        if (b[i] == 'A')
        {
            pref_b[0][i] = i > 0 ? pref_b[0][i - 1] + 1 : 1;
        }
        else pref_b[0][i] = i > 0 ? pref_b[0][i - 1] : 0;

        if (b[i] == 'T')
        {
            pref_b[1][i] = i > 0 ? pref_b[1][i - 1] + 1 : 1;
        }
        else pref_b[1][i] = i > 0 ? pref_b[1][i - 1] : 0;

        if (a[i] != b[i])
        {
            pref[i] = i > 0 ? pref[i - 1] + 1 : 1;
        }
        else pref[i] = i > 0 ? pref[i - 1] : 0;
    }
}

bool validate(int x, int y)
{
    int br_aA = x > 0 ? pref_a[0][y] - pref_a[0][x - 1] : pref_a[0][y];
    int br_aT = x > 0 ? pref_a[1][y] - pref_a[1][x - 1] : pref_a[1][y];
    //cout << br_aA << " " << br_aT << endl;

    int br_bA = x > 0 ? pref_b[0][y] - pref_b[0][x - 1] : pref_b[0][y];
    int br_bT = x > 0 ? pref_b[1][y] - pref_b[1][x - 1] : pref_b[1][y];
    //cout << br_bA << " " << br_bT << endl;

    return (br_aA == br_bA && br_aT == br_bT);
}

int get_distance(int x, int y)
{
    if (!validate(x, y)) return -1;
    int br = x > 0 ? pref[y] - pref[x - 1] : pref[y];
    return br / 2;
}



/*
6 3
ATACAT
ACTATA
1 3
4 5
3 5


2
1
-1

2 1
AA
TT
0 1
*/
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...