Submission #621022

#TimeUsernameProblemLanguageResultExecution timeMemory
621022amunduzbaevMutating DNA (IOI21_dna)C++17
100 / 100
41 ms5436 KiB
#include "dna.h" #ifndef EVAL #include "grader.cpp" #endif #include "bits/stdc++.h" using namespace std; #define ar array const int N = 1e5 + 5; ar<int, 4> pref[N]; void init(string a, string b) { int n = a.size(); for(int i=0;i<n;i++){ if(i) pref[i] = pref[i-1]; if(a[i] == b[i]) pref[i][3]++; else { if(a[i] == 'A' && b[i] == 'T') pref[i][0]++; if(a[i] == 'T' && b[i] == 'C') pref[i][1]++; if(a[i] == 'C' && b[i] == 'A') pref[i][2]++; swap(a[i], b[i]); if(a[i] == 'A' && b[i] == 'T') pref[i][0]--; if(a[i] == 'T' && b[i] == 'C') pref[i][1]--; if(a[i] == 'C' && b[i] == 'A') pref[i][2]--; } } } int get_distance(int x, int y) { ar<int, 4> a = pref[y]; if(x){ for(int t=0;t<4;t++) a[t] -= pref[x-1][t]; } if(a[0] == a[1] && a[1] == a[2]){ //~ cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<"\n"; int res = y - x + 1 - a[3]; a[0] = abs(a[0]); assert((res - a[0] * 3) % 2 == 0); res = (res - a[0] * 3) / 2 + a[0] * 2; return res; } 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...