Submission #783680

#TimeUsernameProblemLanguageResultExecution timeMemory
783680mousebeaverMutating DNA (IOI21_dna)C++17
0 / 100
25 ms5520 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; const int N = 100000; int diff[N]; int Aa[N]; int Ca[N]; int Ab[N]; int Cb[N]; void init(std::string a, std::string b) { int n = a.length(); for(int i = 0; i < n; i++) { diff[i] = 0; Aa[i] = 0; Ca[i] = 0; Ab[i] = 0; Cb[i] = 0; } diff[0] = (a[0] != b[0]); Aa[0] = (a[0] == 'A'); Ca[0] = (a[0] == 'C'); Ab[0] = (b[0] == 'A'); Cb[0] = (b[0] == 'C'); for(int i = 1; i < n; i++) { Aa[i] = Aa[i-1]+(a[i] == 'A'); Ca[i] = Ca[i-1]+(a[i] == 'C'); Ab[i] = Ab[i-1]+(b[i] == 'A'); Cb[i] = Cb[i-1]+(b[i] == 'C'); diff[i] = diff[i-1]+(a[i] != b[i]); } } int get_distance(int x, int y) { if(Aa[y] - (x == 0 ? 0 : Aa[x-1]) != Ab[y] - (x== 0 ? 0 : Ab[x-1]) || Ca[y] - (x == 0 ? 0 : Ca[x-1]) != Cb[y] - (x== 0 ? 0 : Cb[x-1])) { return -1; } return diff[y] - (x == 0 ? 0 : diff[x-1]) - 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...