Submission #446667

#TimeUsernameProblemLanguageResultExecution timeMemory
446667onlk97Mutating DNA (IOI21_dna)C++17
100 / 100
53 ms6784 KiB
#include "dna.h" #include <cstdio> #include <cassert> #include <string> #include <vector> #include <algorithm> using namespace std; vector <int> ac,ca,ct,tc,ta,at; void init(string a,string b) { ac.push_back(0); ca.push_back(0); ct.push_back(0); tc.push_back(0); ta.push_back(0); at.push_back(0); for (int i = 0; i < a.size(); i++) { ac.push_back(ac.back()); ca.push_back(ca.back()); ct.push_back(ct.back()); tc.push_back(tc.back()); ta.push_back(ta.back()); at.push_back(at.back()); if (a[i] == 'A' && b[i] == 'C') { ac.back()++; } else if (a[i] == 'C' && b[i] == 'A') { ca.back()++; } else if (a[i] == 'C' && b[i] == 'T') { ct.back()++; } else if (a[i] == 'T' && b[i] == 'C') { tc.back()++; } else if (a[i] == 'T' && b[i] == 'A') { ta.back()++; } else if (a[i] == 'A' && b[i] == 'T') { at.back()++; } } } int get_distance(int x, int y) { x++; y++; int a = ac[y] - ac[x-1], b = ca[y] - ca[x-1]; int c = ct[y] - ct[x-1], d = tc[y] - tc[x-1]; int e = ta[y] - ta[x-1], f = at[y] - at[x-1]; int mini, ans = 0; mini = min(a, b); a -= mini; b -= mini; ans += mini; mini = min(c, d); c -= mini; d -= mini; ans += mini; mini = min(e, f); e -= mini; f -= mini; ans += mini; mini = min({a, c, e}); a -= mini; c -= mini; e -= mini; ans += 2 * mini; mini = min({b, d, f}); b -= mini; d -= mini; f -= mini; ans += 2 * mini; if (a || b || c || d || e || f) { return -1; } else { return ans; } }

Compilation message (stderr)

dna.cpp: In function 'void init(std::string, std::string)':
dna.cpp:13:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for (int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
#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...