Submission #811161

#TimeUsernameProblemLanguageResultExecution timeMemory
811161math_rabbit_1028Mutating DNA (IOI21_dna)C++17
35 / 100
29 ms6356 KiB
#include "dna.h" #include <bits/stdc++.h> using namespace std; int cnt[101010][3], dif[101010][6]; void init(std::string a, std::string b) { for (int i = 0; i < a.length(); i++) { cnt[i + 1][0] = cnt[i][0]; cnt[i + 1][1] = cnt[i][1]; cnt[i + 1][2] = cnt[i][2]; if (a[i] == 'A') cnt[i + 1][0]++; if (a[i] == 'C') cnt[i + 1][1]++; if (a[i] == 'T') cnt[i + 1][2]++; if (b[i] == 'A') cnt[i + 1][0]--; if (b[i] == 'C') cnt[i + 1][1]--; if (b[i] == 'T') cnt[i + 1][2]--; dif[i + 1][0] = dif[i][0]; dif[i + 1][1] = dif[i][1]; dif[i + 1][2] = dif[i][2]; dif[i + 1][3] = dif[i][3]; dif[i + 1][4] = dif[i][4]; dif[i + 1][5] = dif[i][5]; if (a[i] == 'A' && b[i] == 'C') dif[i + 1][0]++; if (a[i] == 'A' && b[i] == 'T') dif[i + 1][1]++; if (a[i] == 'C' && b[i] == 'A') dif[i + 1][2]++; if (a[i] == 'C' && b[i] == 'G') dif[i + 1][3]++; if (a[i] == 'T' && b[i] == 'A') dif[i + 1][4]++; if (a[i] == 'T' && b[i] == 'C') dif[i + 1][5]++; } } int get_distance(int x, int y) { if (cnt[x][0] != cnt[y + 1][0]) return -1; if (cnt[x][1] != cnt[y + 1][1]) return -1; if (cnt[x][2] != cnt[y + 1][2]) return -1; int ans = 0; ans += min(dif[y + 1][0] - dif[x][0], dif[y + 1][2] - dif[x][2]); ans += min(dif[y + 1][1] - dif[x][1], dif[y + 1][4] - dif[x][4]); ans += min(dif[y + 1][3] - dif[x][3], dif[y + 1][5] - dif[x][5]); ans += 2 * abs(dif[y + 1][0] - dif[x][0] - dif[y + 1][2] + dif[x][2]); return ans; }

Compilation message (stderr)

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