Submission #548724

#TimeUsernameProblemLanguageResultExecution timeMemory
548724esomerMutating DNA (IOI21_dna)C++17
56 / 100
37 ms5768 KiB
#include<bits/stdc++.h> #include "dna.h" using namespace std; vector<tuple<int, int, int>> prefix1; vector<tuple<int, int, int>> prefix2; vector<int> prefix; int n; void init(string a, string b) { n = a.size(); prefix.resize(n); prefix1.resize(n); prefix2.resize(n); for(int i = 0; i < n; i++){ if(i == 0){ prefix1[i] = {0, 0, 0}; prefix2[i] = {0, 0, 0}; if(a[i] == 'A'){ get<0> (prefix1[i])++; }else if(a[i] == 'T'){ get<1>(prefix1[i])++; }else get<2> (prefix1[i])++; if(b[i] == 'A'){ get<0> (prefix2[i])++; }else if(b[i] == 'T'){ get<1>(prefix2[i])++; }else get<2> (prefix2[i])++; }else{ prefix1[i] = prefix1[i - 1]; prefix2[i] = prefix2[i - 1]; if(a[i] == 'A'){ get<0> (prefix1[i])++; }else if(a[i] == 'T'){ get<1>(prefix1[i])++; }else get<2> (prefix1[i])++; if(b[i] == 'A'){ get<0> (prefix2[i])++; }else if(b[i] == 'T'){ get<1>(prefix2[i])++; }else get<2> (prefix2[i])++; } if(a[i] != b[i]){ if(i == 0) prefix[i] = 1; else prefix[i] = prefix[i-1] + 1; }else{ if(i == 0) prefix[i] = 0; else prefix[i] = prefix[i-1]; } } } int get_distance(int x, int y) { int da, db; if(x > 0) da = get<0> (prefix1[y]) - get<0> (prefix1[x-1]); else da = get<0> (prefix1[y]); if(x > 0) db = get<0> (prefix2[y]) - get<0> (prefix2[x-1]); else db = get<0> (prefix2[y]); if(da != db) return -1; if(x > 0) da = get<1> (prefix1[y]) - get<1> (prefix1[x-1]); else da = get<1> (prefix1[y]); if(x > 0) db = get<1> (prefix2[y]) - get<1> (prefix2[x-1]); else db = get<1> (prefix2[y]); if(da != db) return -1; if(x > 0) da = get<2> (prefix1[y]) - get<2> (prefix1[x-1]); else da = get<2> (prefix1[y]); if(x > 0) db = get<2> (prefix2[y]) - get<2> (prefix2[x-1]); else db = get<2> (prefix2[y]); if(da != db) return -1; int d; if(x > 0) d = prefix[y] - prefix[x-1]; else d = prefix[y]; if(d % 2 != 0) return d / 2 + 1; else return d / 2; }
#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...