Submission #472365

#TimeUsernameProblemLanguageResultExecution timeMemory
472365aris12345678Mutating DNA (IOI21_dna)C++17
35 / 100
98 ms5808 KiB
#include "dna.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN = 100005;
int pref[mxN], prefa1[mxN], prefc1[mxN], prefa2[mxN], prefc2[mxN];

void init(string a, string b) {
    int n = int(a.length());
    for(int i = 0; i < n; i++) {
        pref[i+1] = pref[i], prefa1[i+1] = prefa1[i], prefc1[i+1] = prefc1[i], prefa2[i+1] = prefa2[i], prefc2[i+1] = prefc2[i];
        if(a[i] != b[i])
            pref[i+1]++;
        if(a[i] == 'A')
            prefa1[i+1]++;
        if(a[i] == 'C')
            prefc1[i+1]++;
        if(b[i] == 'A')
            prefa2[i+1]++;
        if(b[i] == 'C')
            prefc2[i+1]++;
    }
}

int ceil(int a, int b) {
    return a%b == 0 ? a/b : a/b+1;
}

int get_distance(int x, int y) {
    y++;
    if(prefa2[y]-prefa2[x] != prefa1[y]-prefa1[x] || prefc2[y]-prefc2[x] != prefc1[y]-prefc2[x])
        return -1;
    return ceil(pref[y]-pref[x], 2);
}
/*
int main() {
    string a, b;
    cin >> a >> b;
    init(a, b);
    int q;
    scanf("%d", &q);
    while(q--) {
        int x, y;
        scanf("%d %d", &x, &y);
        printf("%d\n", get_distance(x, y));
    }
    return 0;
}
*/
#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...